public virtual DecodedObject <object> decodeChoice(DecodedObject <object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream) { object choice = createInstanceForElement(objectClass, elementInfo); DecodedObject <object> val = null; PropertyInfo[] fields = elementInfo.getProperties(objectClass); int fieldIdx = 0; foreach (PropertyInfo field in fields) { ElementInfo info = new ElementInfo(); info.AnnotatedClass = field; if (elementInfo.hasPreparedInfo()) { info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx); } else { info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field); } val = decodeClassType(decodedTag, field.PropertyType, info, stream); fieldIdx++; if (val != null) { invokeSelectMethodForField(field, choice, val.Value, info); break; } ; } if (val == null && !CoderUtils.isOptional(elementInfo)) { throw new System.ArgumentException("The choice '" + objectClass.ToString() + "' does not have a selected item!"); } else { return(new DecodedObject <object>(choice, val != null?val.Size:0)); } }