예제 #1
0
        public void TestAssemblyInspection()
        {
            var inspector = new ModelInspector();

            // Inspect the HL7.Fhir.Model assembly
            inspector.Import(typeof(Resource).Assembly);

            // Check for presence of some basic ingredients
            Assert.IsNotNull(inspector.FindClassMappingForResource("patient"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("HumanName"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("code"));
            Assert.IsNotNull(inspector.FindClassMappingForFhirDataType("boolean"));

            // Verify presence of nested enumerations
            Assert.IsNotNull(inspector.FindEnumMappingByType(typeof(Address.AddressUse)));

            // Should have skipped abstract classes
            Assert.IsNull(inspector.FindClassMappingForResource("ComplexElement"));
            Assert.IsNull(inspector.FindClassMappingForResource("Element"));
            Assert.IsNull(inspector.FindClassMappingForResource("Resource"));

            // The open generic Code<> should not be there
            var codeOfT = inspector.FindClassMappingByType(typeof(Code <>));

            Assert.IsNull(codeOfT);
        }
        internal Base Deserialize(Type elementType, Base existing = null)
        {
            var mapping = _inspector.FindClassMappingByType(elementType);

            if (mapping == null)
            {
                throw Error.Format("Asked to deserialize unknown type '" + elementType.Name + "'", _current);
            }

            return(Deserialize(mapping, existing));
        }
예제 #3
0
        public void TestAssemblyInspection()
        {
            var inspector = new ModelInspector(ModelInspector.R3_VERSION);

            // Inspect the HL7.Fhir.Model common assembly
            inspector.Import(typeof(Resource).GetTypeInfo().Assembly);

            // Check for presence of some basic ingredients
            Assert.IsNotNull(inspector.FindClassMappingByName("Meta"));
            Assert.IsNotNull(inspector.FindClassMappingByType(typeof(Code)));
            Assert.IsNotNull(inspector.FindClassMappingByName("boolean"));

            // Should also have found the abstract classes
            Assert.IsNotNull(inspector.FindClassMappingByName("Element"));
            Assert.IsNotNull(inspector.FindClassMappingByType(typeof(Resource)));

            // The open generic Code<> should not be there
            var codeOfT = inspector.FindClassMappingByType(typeof(Code <>));

            Assert.IsNull(codeOfT);
        }
예제 #4
0
        internal Base Deserialize(Base existing = null)
        {
            if (_current.InstanceType is null)
            {
                throw Error.Format("Underlying data source was not able to provide the actual instance type of the resource.");
            }

            var mapping = _inspector.FindClassMappingByType(_current.InstanceType);

            if (mapping == null)
            {
                RaiseFormatError($"Asked to deserialize unknown type '{_current.InstanceType}'", _current.Location);
            }

            return(Deserialize(mapping, existing));
        }
예제 #5
0
        public void TypeDataTypeNameResolving()
        {
            var inspector = new ModelInspector();

            inspector.ImportType(typeof(AnimalName));
            inspector.ImportType(typeof(NewAnimalName));

            var result = inspector.FindClassMappingForFhirDataType("animalname");

            Assert.IsNotNull(result);
            Assert.AreEqual(result.NativeType, typeof(NewAnimalName));

            // Validate a mapping for a type will return the newest registration
            result = inspector.FindClassMappingByType(typeof(AnimalName));
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NewAnimalName), result.NativeType);
        }
예제 #6
0
 public FhirbaseJsonReader(object json, Type t)
 {
     m_reader  = new JsonTextReader(new StringReader(json as string));
     m_mapping = s_modelInspector.FindClassMappingByType(t);
 }
예제 #7
0
 public FhirbaseJsonWriter(StringWriter sw, Type t) : base(sw)
 {
     m_mapping = s_modelInspector.FindClassMappingByType(t);
 }