public object Deserialize(PropertyMapping prop, string memberName, object existing=null) { if (prop == null) throw Error.ArgumentNull("prop"); // ArrayMode avoid the dispatcher making nested calls into the RepeatingElementReader again // when reading array elements. FHIR does not support nested arrays, and this avoids an endlessly // nesting series of dispatcher calls if (!_arrayMode && prop.IsCollection) { if (existing != null && !(existing is IList) ) throw Error.Argument("existing", "Can only read repeating elements into a type implementing IList"); var reader = new RepeatingElementReader(_current); return reader.Deserialize(prop, memberName, (IList)existing); } // If this is a primitive type, no classmappings and reflection is involved, // just parse the primitive from the input // NB: no choices for primitives! if(prop.IsPrimitive) { var reader = new PrimitiveValueReader(_current); return reader.Deserialize(prop.ElementType); } // A Choice property that contains a choice of any resource // (as used in Resource.contained) if(prop.Choice == ChoiceType.ResourceChoice) { var reader = new ResourceReader(_current); return reader.Deserialize(null); } ClassMapping mapping; // Handle other Choices having any datatype or a list of datatypes if(prop.Choice == ChoiceType.DatatypeChoice) { // For Choice properties, determine the actual type of the element using // the suffix of the membername (i.e. deceasedBoolean, deceasedDate) // This function implements type substitution. mapping = determineElementPropertyType(prop, memberName); } // Else use the actual return type of the property else { mapping = _inspector.ImportType(prop.ElementType); } if (existing != null && !(existing is Resource) && !(existing is Element) ) throw Error.Argument("existing", "Can only read complex elements into types that are Element or Resource"); var cplxReader = new ComplexTypeReader(_current); return cplxReader.Deserialize(mapping, (Base)existing); }
public object Deserialize(PropertyMapping prop, string memberName, object existing = null) { if (prop == null) { throw Error.ArgumentNull(nameof(prop)); } // ArrayMode avoid the dispatcher making nested calls into the RepeatingElementReader again // when reading array elements. FHIR does not support nested arrays, and this avoids an endlessly // nesting series of dispatcher calls if (!_arrayMode && prop.IsCollection) { if (existing != null && !(existing is IList)) { throw Error.Argument(nameof(existing), "Can only read repeating elements into a type implementing IList"); } var reader = new RepeatingElementReader(_current, Settings); return(reader.Deserialize(prop, memberName, (IList)existing)); } // If this is a primitive type, no classmappings and reflection is involved, // just parse the primitive from the input // NB: no choices for primitives! if (prop.IsPrimitive) { var reader = new PrimitiveValueReader(_current); return(reader.Deserialize(prop.ElementType)); } // A Choice property that contains a choice of any resource // (as used in Resource.contained) if (prop.Choice == ChoiceType.ResourceChoice) { var reader = new ResourceReader(_current, Settings); return(reader.Deserialize(null)); } ClassMapping mapping; // Handle other Choices having any datatype or a list of datatypes if (prop.Choice == ChoiceType.DatatypeChoice) { // For Choice properties, determine the actual type of the element using // the suffix of the membername (i.e. deceasedBoolean, deceasedDate) // This function implements type substitution. mapping = determineElementPropertyType(prop, memberName); } // Else use the actual return type of the property else { mapping = _inspector.ImportType(prop.ElementType); } if (existing != null && !(existing is Resource) && !(existing is Element)) { throw Error.Argument(nameof(existing), "Can only read complex elements into types that are Element or Resource"); } var cplxReader = new ComplexTypeReader(_current, Settings); return(cplxReader.Deserialize(mapping, (Base)existing)); }