public virtual int encodeSequence(object obj, Stream stream, ElementInfo elementInfo) { int resultSize = 0; PropertyInfo[] fields = elementInfo.getProperties(obj.GetType()); int fieldIdx = 0; foreach (PropertyInfo field in fields) { resultSize += encodeSequenceField(obj, fieldIdx++, field, stream, elementInfo); } return(resultSize); }
public virtual DecodedObject <object> decodeChoice(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, 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 ArgumentException("The choice '" + objectClass + "' does not have a selected item!"); } else { return(new DecodedObject <object>(choice, val != null ? val.Size : 0)); } }
protected ElementInfo getChoiceSelectedElement(Object obj, ElementInfo elementInfo) { ElementInfo info = null; PropertyInfo[] fields = elementInfo.getProperties(obj.GetType()); int fieldIdx = 0; foreach (PropertyInfo field in fields) { info = new ElementInfo(); info.AnnotatedClass = field; if (elementInfo.hasPreparedInfo()) { info.PreparedInfo = (elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx)); } else { info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field); } if (invokeSelectedMethodForField(field, obj, info)) { break; } else { info = null; } fieldIdx++; } if (info == null) { throw new ArgumentException("The choice '" + obj + "' does not have a selected item!"); } return(info); }
public virtual DecodedObject <object> decodeSequence(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream) { object sequence = createInstanceForElement(objectClass, elementInfo); initDefaultValues(sequence); DecodedObject <object> fieldTag = null; int maxSeqLen = elementInfo.MaxAvailableLen; int sizeOfSequence = 0; if (maxSeqLen == -1 || maxSeqLen > 0) { fieldTag = decodeTag(stream); if (fieldTag != null) { sizeOfSequence += fieldTag.Size; } } PropertyInfo[] fields = elementInfo.getProperties(objectClass); for (int i = 0; i < fields.Length; i++) { PropertyInfo field = fields[i]; DecodedObject <object> obj = decodeSequenceField( fieldTag, sequence, i, field, stream, elementInfo, true ); if (obj != null) { sizeOfSequence += obj.Size; bool isAny = false; if (i + 1 == fields.Length - 1) { ElementInfo info = new ElementInfo(); info.AnnotatedClass = (fields[i + 1]); info.MaxAvailableLen = (elementInfo.MaxAvailableLen); if (elementInfo.hasPreparedInfo()) { info.PreparedInfo = (elementInfo.PreparedInfo.getPropertyMetadata(i + 1)); } else { info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(fields[i + 1]); } isAny = CoderUtils.isAnyField(fields[i + 1], info); } if (maxSeqLen != -1) { elementInfo.MaxAvailableLen = (maxSeqLen - sizeOfSequence); } if (!isAny) { if (i < fields.Length - 1) { if (maxSeqLen == -1 || elementInfo.MaxAvailableLen > 0) { fieldTag = decodeTag(stream); if (fieldTag != null) { sizeOfSequence += fieldTag.Size; } else { break; } } else { fieldTag = null; } } } } ; } return(new DecodedObject <object>(sequence, sizeOfSequence)); }