/// <summary> /// Build a POCO from an ISourceNode. /// </summary> /// <param name="source"></param> /// <param name="dataType">Optional. Type of POCO to build. Should be one of the generated POCO classes.</param> /// <returns></returns> /// <remarks>If <paramref name="dataType"/> is not supplied, or is <code>Resource</code> or <code>DomainResource</code>, /// the builder will try to determine the actual type to create from the <paramref name="source"/>. </remarks> public Base BuildFrom(ISourceNode source, Type dataType = null) { if (source == null) { throw Error.ArgumentNull(nameof(source)); } return(BuildFrom(source, dataType != null ? findMappingOrReport(dataType) : null)); ClassMapping findMappingOrReport(Type t) { var typeFound = _inspector.FindClassMapping(dataType); if (typeFound == null) { ExceptionHandler.NotifyOrThrow(this, ExceptionNotification.Error( new StructuralTypeException($"While building a POCO: The .NET type '{dataType.Name}' does not represent a FHIR type."))); return(null); } return(typeFound); } }
public void TestResourceNameResolving() { var inspector = new ModelInspector(Specification.FhirRelease.STU3); inspector.ImportType(typeof(Way)); inspector.ImportType(typeof(Way2)); var way = inspector.FindClassMapping("Way"); Assert.IsNotNull(way); Assert.AreEqual(way.NativeType, typeof(Way)); var way2 = inspector.FindClassMapping("Way2"); Assert.IsNotNull(way2); Assert.AreEqual(way2.NativeType, typeof(Way2)); var noway = inspector.FindClassMapping("nonexistent"); Assert.IsNull(noway); }
private ClassMapping getMappingForType(string memberName, string typeName) { // NB: this will return the latest type registered for that name, so supports type mapping/overriding // Maybe we should Import the types present on the choice, to make sure they are available. For now // assume the caller has Imported all types in the right (overriding) order. ClassMapping result = _inspector.FindClassMapping(typeName); if (result == null) { ComplexTypeReader.RaiseFormatError( $"Encountered polymorph member {memberName}, which uses unknown datatype {typeName}", _current.Location); } return(result); }
public void TestAssemblyInspection() { var inspector = new ModelInspector(Specification.FhirRelease.STU3); // Inspect the HL7.Fhir.Model common assembly inspector.Import(typeof(Resource).GetTypeInfo().Assembly); // Check for presence of some basic ingredients Assert.IsNotNull(inspector.FindClassMapping("Meta")); Assert.IsNotNull(inspector.FindClassMapping(typeof(Code))); Assert.IsNotNull(inspector.FindClassMapping("boolean")); // Should also have found the abstract classes Assert.IsNotNull(inspector.FindClassMapping("Element")); Assert.IsNotNull(inspector.FindClassMapping(typeof(Resource))); // The open generic Code<> should not be there var codeOfT = inspector.FindClassMapping(typeof(Code <>)); Assert.IsNull(codeOfT); }