/// <summary> /// Create a new instance of FieldMetaData with a given MemberInfo. /// </summary> /// <param name="outRef">Indicates the reference of the out object that hold this constraint.</param> /// <param name="info"></param> /// <remarks> /// AttachedTag, Constraint will be set automatically by reflection. /// </remarks> protected Asn1ConstraintedFieldMetadata(Asn1Object outRef, MemberInfo info) { OutReference = outRef; MemberInfo = info; //Get AttachedTag AttachedTag = null; var attrs = MemberInfo.GetCustomAttributes(typeof(Asn1Tag), true); if (attrs.Length != 0) { //Only the first tag is valid. Asn1Tag tag = attrs[0] as Asn1Tag; if (tag.TagType != Asn1TagType.Context && tag.TagType != Asn1TagType.Application) { throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " Only Context-Specific tag and Application tag are allowed."); } AttachedTag = tag; } //Get Constraint Constraint = GetConstraints(); }
public SearchResponse(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public Filter(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
/// <summary> /// Initializes a new instance of the Asn1Choice class with a given value. /// </summary> /// <param name="choiceIndex">The corresponding index of the value in the choices.</param> /// <param name="obj"></param> protected Asn1Choice(long? choiceIndex, Asn1Object obj) { CollectMetadata(); SetData(choiceIndex, obj); }
/// <summary> /// Create a new instance of FieldMetaData with a given MemberInfo. /// </summary> /// <param name="outRef">Specifies the out reference of the field.</param> /// <param name="info"></param> /// <remarks> /// AttachedTag, Optional, Constraint will be set automatically by reflection. /// </remarks> public ChoiceMetaData(Asn1Object outRef, MemberInfo info) : base(outRef, info) { //Get Optional var attrs = MemberInfo.GetCustomAttributes(typeof(Asn1ChoiceElement), true); if (attrs == null || attrs.Length == 0) { throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " No choice element in CHOICE is defined."); } AttachedIndex = ((Asn1ChoiceElement)attrs[0]).Index; }
public ConnectGCCPDU(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public NegotiationToken2(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public LDAPMessage_protocolOp(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
/// <summary> /// Gets instances of all the choices in the structure. /// </summary> /// <returns>An array that contains the instances.</returns> private Asn1Object[] GetChoiceTypeInstances() { Asn1Object[] allChoices = new Asn1Object[fieldsMemberInfo.Length]; for (int i = 0; i < fieldsMemberInfo.Length; i++) { if (fieldsMemberInfo[i].MemberType == MemberTypes.Property) { allChoices[i] = Activator.CreateInstance((fieldsMemberInfo[i] as PropertyInfo).PropertyType) as Asn1Object; } else if (fieldsMemberInfo[i].MemberType == MemberTypes.Field) { allChoices[i] = Activator.CreateInstance((fieldsMemberInfo[i] as FieldInfo).FieldType) as Asn1Object; } else { throw new Asn1UnreachableExcpetion(ExceptionMessages.Unreachable); } } return allChoices; }
/// <summary> /// Stores the data in the CHOICE structure. /// </summary> /// <param name="index">The corresponding index of the choices defined in the type for obj. /// Use the const value defined in the class as this parameter.</param> /// <param name="obj">The data to be stored in the CHOICE.</param> public void SetData(long? index, Asn1Object obj) { if (index == undefinedIndex) { this.currentChoice = undefinedIndex; this.choiceIndexInFieldsMemberInfo = undefinedIndex; return; } if (allowedIndices.Contains(index)) { for (int i = 0; i < fieldsMemberInfo.Length; i++) { var attrs = fieldsMemberInfo[i].GetCustomAttributes(typeof(Asn1ChoiceElement), true); if ((attrs[0] as Asn1ChoiceElement).Index == index) { currentChoice = index; choiceIndexInFieldsMemberInfo = i; //Store the data if (fieldsMemberInfo[i].MemberType == MemberTypes.Property) { (fieldsMemberInfo[i] as PropertyInfo).SetValue(this, obj, null); } else if (fieldsMemberInfo[i].MemberType == MemberTypes.Field) { (fieldsMemberInfo[i] as FieldInfo).SetValue(this, obj); } else { throw new Asn1UnreachableExcpetion(ExceptionMessages.Unreachable); } break; } } } else { throw new Asn1InvalidArgument(ExceptionMessages.InvalidChoiceIndex); } }
/// <summary> /// Gets new instances of all the fields in the structure. /// </summary> /// <returns>An array that contains the instances.</returns> /// <remarks>This method is used when decoding. All the elements in the returned array don't have data.</remarks> private Asn1Object[] GetFieldsTypeInstances() { Asn1Object[] allFields = new Asn1Object[fieldsMemberInfo.Length]; for (int i = 0; i < fieldsMemberInfo.Length; i++) { if (fieldsMemberInfo[i].MemberType == MemberTypes.Property) { allFields[i] = Activator.CreateInstance((fieldsMemberInfo[i] as PropertyInfo).PropertyType) as Asn1Object; } else if (fieldsMemberInfo[i].MemberType == MemberTypes.Field) { allFields[i] = Activator.CreateInstance((fieldsMemberInfo[i] as FieldInfo).FieldType) as Asn1Object; } else { //Unreachable. Ensured by the AttributeUsage of Asn1Field.. throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " Asn1Field property could only be used in properties or fields."); } if (allFields[i] == null) { throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " Can't create instance for member " + fieldsMemberInfo[i].Name + " in class " + this.GetType().Name + "."); } } return allFields; }
/// <summary> /// Set the Constraint stored in this instance to a specific object. /// </summary> /// <param name="obj"></param> private void SetObjectConstraint(Asn1Object obj) { if (Constraint != null) { if (IsInheritedFrom(typeof(Asn1Integer))) { (obj as Asn1Integer).Constraints = Constraint as Asn1IntegerBound; } else if (IsInheritedFrom(typeof(Asn1String))) { (obj as Asn1OctetString).Constraint = Constraint as Asn1StringConstraint; } //TODO: add more when needed. } }
/// <summary> /// Create a new instance of FieldMetaData with a given MemberInfo. /// </summary> /// <param name="outRef">Stores the out reference of the object.</param> /// <param name="info"></param> /// <remarks> /// AttachedTag, Optional, Constraint will be set automatically by reflection. /// </remarks> public FieldMetaData(Asn1Object outRef, MemberInfo info) : base(outRef, info) { //Get Optional var attrs = MemberInfo.GetCustomAttributes(typeof(Asn1Field), true); if (attrs == null || attrs.Length == 0) { throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " No Asn1Field is specified."); } Optional = (attrs[0] as Asn1Field).Optional; }
public DomainMCSPDU(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public BindRequest_authentication(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public Key(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public StatsResponseValueV4_element_choice(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public PA_FX_FAST_REPLY(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
/// <summary> /// Stores the data in the CHOICE structure. /// </summary> /// <param name="index">The corresponding index of the choices defined in the type for obj. /// Use the const value defined in the class as this parameter.</param> /// <param name="obj">The data to be stored in the CHOICE.</param> public void SetData(long? index, Asn1Object obj) { if (index == UndefinedIndex) { SelectedChoice = UndefinedIndex; choiceIndexInFieldsMemberInfo = UndefinedIndex; return; } if (definedAllowedIndices.Contains(index)) { if (HasExternalObjects && index == definedAllowedIndices[definedAllowedIndices.Count - 1]) { throw new NotImplementedException("Assigning value to external objects is not implemented."); } for (int i = 0; i < metaDatas.Length; i++) { if (metaDatas[i].AttachedIndex == index) { SelectedChoice = index; choiceIndexInFieldsMemberInfo = i; //Store the data metaDatas[i].ValueInOutObject = obj; break; } } } else { throw new Asn1InvalidArgument(ExceptionMessages.InvalidChoiceIndex); } }
public SubstringFilter_substrings_element(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }
public AuthenticationChoice(long? choiceIndex, Asn1Object obj) : base(choiceIndex, obj) { }