Exemplo n.º 1
0
        public override int encodeEnumItem(object enumConstant, Type enumClass, Stream stream, ElementInfo elementInfo)
        {
            ASN1EnumItem enumObj = elementInfo.getAttribute <ASN1EnumItem>();
            //int min = 0, max = enumClass.GetFields().Length, val = 0;
            int min = 0, max = 0, val = 0;

            foreach (FieldInfo enumItem in enumClass.GetFields())
            {
                if (CoderUtils.isAttributePresent <ASN1EnumItem>(enumItem))
                {
                    ASN1EnumItem enumItemObj = CoderUtils.getAttribute <ASN1EnumItem>(enumItem);
                    if (enumItemObj.Tag == enumObj.Tag)
                    {
                        val = max;
                    }
                    max++; //val++;
                }
            }
            if (max > 0)
            {
                return(encodeConstraintNumber(val, min, max, (BitArrayOutputStream)stream));
            }
            else
            {
                throw new Exception("Unable to present any enum item!");
            }
        }
Exemplo n.º 2
0
 public override void setParentAnnotated(ICustomAttributeProvider parent)
 {
     if (parent != null)
     {
         if (CoderUtils.isAttributePresent <ASN1String>(parent))
         {
             ASN1String value = CoderUtils.getAttribute <ASN1String>(parent);
             stringType = value.StringType;
         }
     }
 }
Exemplo n.º 3
0
        public override DecodedObject <object> decodeEnumItem(DecodedObject <object> decodedTag, Type objectClass, Type enumClass, ElementInfo elementInfo, Stream stream)
        {
            //int min = 0, max = enumClass.GetFields().Length;
            int min = 0, max = 0;

            foreach (FieldInfo enumItem in enumClass.GetFields())
            {
                if (CoderUtils.isAttributePresent <ASN1EnumItem>(enumItem))
                {
                    max++;
                }
            }

            if (max <= 0)
            {
                throw new Exception("Unable to present any enum item!");
            }

            int enumItemIdx = (int)decodeConstraintNumber(min, max - 1, (BitArrayInputStream)stream);
            DecodedObject <object> result = new DecodedObject <object>();
            int idx = 0;

            foreach (FieldInfo enumItem in enumClass.GetFields())
            {
                if (CoderUtils.isAttributePresent <ASN1EnumItem>(enumItem))
                {
                    if (idx++ == enumItemIdx)
                    {
                        ASN1EnumItem enumItemObj = CoderUtils.getAttribute <ASN1EnumItem>(enumItem);
                        result.Value = enumItemObj.Tag;
                        break;
                    }
                }
            }
            return(result);
        }