File

projects/wms-framework/src/lib/baseframework/serialization.ts

Description

Identification used for datacontract deserialization

Extends

MetadataAttribute

Index

Methods

Constructor

constructor(props?: DataContractIdProperties)

Creates an instance of DataContractId.

Parameters :
Name Type Optional
props DataContractIdProperties Yes

Methods

Public OnAppliedTo
OnAppliedTo(target: any)
Inherited from MetadataAttribute

Callback method called when applying this metadata item to an object

Parameters :
Name Type Optional
target any No
Returns : void
import { RuntimeTypeInfo } from './ReflectionSupport';
import { SmStream } from '../helpers/StreamsSupport';
import { Debugger } from '../diagnostics/Debugger';
import { MetadataAttribute } from './MetadataAttribute';
import { TypeResolver } from '../helpers/TypeResolver';

/**
 * DataContract serializer
 *
 * @export
 * @class DataContractSerializer
 * TODO: Additional types System.Runtime.Serialization.XmlObjectSerializer
 * @wType System.Runtime.Serialization.DataContractSerializer
 */
export class DataContractSerializer {
  constructor(private type: RuntimeTypeInfo, private type2?: RuntimeTypeInfo) {}
  /**
   * Reads object
   * NOT IMPLEMENTED
   *
   * @param {SmStream} str
   * @returns {unknown}
   * @memberof DataContractSerializer
   * @wNoMap
   */
  public ReadObject(str: SmStream): unknown {
    Debugger.Throw('Not implemented');
    return null;
  }

  /**
   * Writes object
   * NOT IMPLEMENTED
   *
   * @param {SmStream} str
   * @param {unknown} obj
   * @memberof DataCntractSerializer
   * @wNoMap
   */
  public WriteObject(str: SmStream, obj: unknown) {
    Debugger.Throw('Not implemented');
  }
}

/**
 *  Type of the arguments of the constructor of the DataContractId metadata item
 */
export type DataContractIdProperties = {
  /**
   *  Class name
   *
   * @type {string}
   */
  Name?: string;

  /**
   *  Original class namespace
   *
   * @type {string}
   */
  Namespace?: string;
};

/**
 * Identification used for datacontract deserialization
 *
 * @export
 * @class DataContractId
 * @extends {MetadataAttribute}
 * @wType System.Runtime.Serialization.DataContractAttribute
 */
export class DataContractId extends MetadataAttribute {
  /**
   * Creates an instance of DataContractId.
   * @param {DataContractIdProperties} [props]
   * @memberof DataContractId
   */
  constructor(private props?: DataContractIdProperties) {
    super();
  }
  /**
   *  Callback method called when applying this metadata item to an object
   *
   * @param {*} target
   * @memberof DataContractId
   */
  public OnAppliedTo(target: any): void {
    const fullClassName =
      typeof this.props?.Namespace === 'string'
        ? `${this.props.Namespace}.${this.props.Name}`
        : this.props?.Name;
    if (typeof fullClassName === 'string') {
      TypeResolver.regitrateClassInfo(fullClassName, {
        classId: fullClassName,
        type: target,
      });
    }
  }
}

result-matching ""

    No results matching ""