EmberType Class |
Namespace: Lawo.EmberPlusSharp.Ember
public sealed class EmberType
The EmberType type exposes the following members.
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
FromType | Creates a EmberType from type. | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
(Type to EmberType) | Implicitly converts type to a EmberType. |
An EmberType instance contains most of the information that is necessary to read and write a data value of a given type with EmberReader and EmberWriter. Moreover, it also contains the information to convert a data value to and from XML.
An EmberType object is typically created by providing a Type object representing a class that contains two constants describing the type itself and that optionally contains one nested class describing each field. Each of the nested classes in turn contains 3 constants. So, a primitive type (which does not contain any fields) can be represented like e.g. BerBoolean, BerReal, etc. A type with fields, like e.g. the Glow Command, can be described as follows:
internal static class GlowCommand { internal const int InnerNumber = Ember.InnerNumber.FirstApplication + 2; internal const string Name = "Command"; internal static class Number { internal const int OuterNumber = 0; internal const string Name = "number"; internal static readonly EmberId OuterId = EmberId.CreateContextSpecific(OuterNumber); } internal static class DirFieldMask { internal const int OuterNumber = 1; internal const string Name = "dirFieldMask"; internal static readonly EmberId OuterId = EmberId.CreateContextSpecific(OuterNumber); } }
This form of description was chosen so that e.g. code that turns a serialized Glow Command into an in-memory representation can directly use these constants. On the other hand, code that needs to transform a serialized EmBER representation to and from e.g. XML, can easily use reflection to build high performance lookup tables from the information contained in these classes.
The fields of a type can usually unambiguously be identified by an EmberType instance constructed by passing a single Type instance. However, certain DTDs store fields in plain BER sequence or set types. For these fields, it is necessary to also consider one or more parent fields. This is why the constructor also accepts two or more types, where the first types represent the path to the last type.