Generated C# Method Format and Calling Parameters

The signature for a C# XER encode method is as follows:

   public override void Encode (Asn1XerEncoder buffer, string elemName)

The signature for a C# XML encode method is similar:

   public override void Encode (Asn1XmlEncoder buffer, string elemName)

The buffer argument is a reference to an Asn1XerEncoder or Asn1XmlEncoder derived object that describes the buffer or output stream into which a message is to be encoded. Asn1XerEncoder is a base interface for the Asn1XerEncodeBuffer and Asn1XerOutputStream classes. Similarly, Asn1XmlEncoder is an interface to a pure XML version of these base classes. There is no difference which encode method is used: output stream or message buffer. The generated logic is the same, the difference is only in the first parameter of the encode method. This must be created and initialized before calling any encode method. See the description of this class in the C# Run-TimeReference Manual for details on how this class is used.

The elemName argument is a reference to a string containing the element name text. This text is used to form the standard XML angle-bracketed wrapper that is applied to each element in a message. Note the name passed must not contain the angle-brackets (i.e. the < > characters). These will be added by the encode method.

The elemName can be passed in different ways to control how the name is applied. The normal way is to pass a name that is applied as the element name of the element. If null is passed, then the default element name for the referenced ASN.1 built-in type is used. For example, <BOOLEAN> is the default element name for the ASN.1 BOOLEAN type. The complete list of default element names can be found in the X.693 standard. If an empty string is passed (i.e. “”), this tells the encode method to omit the element name string all together and just encode the value (this is similar to implicit tagging in the BER case).

The XER or XML encode methods do not return a value. This is different than the C/C++ version that returns a negative status value to indicate an encoding failure. For C#, errors are reported via the exception mechanism. All ASN1C C# exceptions are derived from the Asn1Exception base class. See the section on exceptions for a complete list and description of the various exceptions that can be thrown. If I/O error occurs then the System.Exception is thrown.