/// <summary> /// Gets the constraint defined for the field by reflection. /// </summary> /// <returns></returns> private Asn1Constraint GetConstraints() { Asn1Constraint Constraint = null; Object[] attrs; if (IsInheritedFrom(typeof(Asn1Integer))) { attrs = MemberInfo.GetCustomAttributes(typeof(Asn1IntegerBound), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1IntegerBound; } } else if (IsInheritedFrom(typeof(Asn1String))) { attrs = MemberInfo.GetCustomAttributes(typeof(Asn1StringConstraint), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1StringConstraint; } } else if (IsInheritedFrom(typeof(Asn1HomogeneousComposition <>))) { attrs = MemberInfo.GetCustomAttributes(typeof(Asn1SizeConstraint), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1SizeConstraint; } } return(Constraint); }
/// <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(); }
/// <summary> /// Gets the constraint defined for the field by reflection. /// </summary> /// <returns></returns> private Asn1Constraint GetConstraints() { Asn1Constraint Constraint = null; Object[] attrs; if (IsInheritedFrom(typeof(Asn1Integer))) { attrs = MemberInfo.GetCustomAttributes(typeof(Asn1IntegerBound), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1IntegerBound; } } else if (IsInheritedFrom(typeof(Asn1String))) { attrs = MemberInfo.GetCustomAttributes(typeof(Asn1StringConstraint), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1StringConstraint; } } else if (IsInheritedFrom(typeof (Asn1HomogeneousComposition<>))) { attrs = MemberInfo.GetCustomAttributes(typeof (Asn1SizeConstraint), true); if (attrs.Length > 0) { Constraint = attrs[0] as Asn1SizeConstraint; } } //TODO: add more when needed. return Constraint; }