Ejemplo n.º 1
0
        public override DecodedObject <object> decodeChoice(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream)
        {
            object choice = createInstanceForElement(objectClass, elementInfo);

            skipAlignedBits(stream);
            PropertyInfo[]         fields       = elementInfo.getProperties(objectClass);
            int                    elementIndex = (int)decodeConstraintNumber(1, fields.Length, (BitArrayInputStream)stream);
            DecodedObject <object> val          = null;

            for (int i = 0; i < elementIndex && i < fields.Length; i++)
            {
                if (i + 1 == elementIndex)
                {
                    PropertyInfo field = fields[i];
                    ElementInfo  info  = new ElementInfo();
                    info.AnnotatedClass = field;
                    if (elementInfo.hasPreparedInfo())
                    {
                        info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(i);
                    }
                    else
                    {
                        info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field);
                    }
                    val = decodeClassType(decodedTag, field.PropertyType, info, stream);
                    if (val != null)
                    {
                        invokeSelectMethodForField(field, choice, val.Value, info);
                    }
                    break;
                }
                ;
            }
            if (val == null && !CoderUtils.isOptional(elementInfo))
            {
                throw new ArgumentException("The choice '" + objectClass + "' does not have a selected item!");
            }
            else
            {
                return(new DecodedObject <object>(choice));
            }
        }