public static ClassMapping Create(Type type) { // checkMutualExclusiveAttributes(type); var result = new ClassMapping { NativeType = type }; if (IsMappableType(type)) { result.Name = collectTypeName(type); result.Profile = getProfile(type); result.IsResource = IsFhirResource(type); result.IsAbstract = type.GetTypeInfo().IsAbstract; result.IsCodeOfT = ReflectionHelper.IsClosedGenericType(type) && ReflectionHelper.IsConstructedFromGenericTypeDefinition(type, typeof(Code <>)); result.IsBackbone = type.CanBeTreatedAsType(typeof(IBackboneElement)); if (!result.IsResource && !String.IsNullOrEmpty(result.Profile)) { throw Error.Argument(nameof(type), "Type {0} is not a resource, so its FhirType attribute may not specify a profile".FormatWith(type.Name)); } inspectProperties(result); return(result); } else { throw Error.Argument(nameof(type), "Type {0} is not marked as a Fhir Resource or datatype using [FhirType]".FormatWith(type.Name)); } }
public static bool TryCreate(Type type, out ClassMapping result, FhirRelease fhirVersion = (FhirRelease)int.MaxValue) { result = null; var typeAttribute = GetAttribute <FhirTypeAttribute>(type.GetTypeInfo(), fhirVersion); if (typeAttribute == null) { return(false); } if (ReflectionHelper.IsOpenGenericTypeDefinition(type)) { Message.Info("Type {0} is marked as a FhirType and is an open generic type, which cannot be used directly to represent a FHIR datatype", type.Name); return(false); } result = new ClassMapping { Name = collectTypeName(typeAttribute, type), IsResource = typeAttribute.IsResource || type.CanBeTreatedAsType(typeof(Resource)), IsCodeOfT = ReflectionHelper.IsClosedGenericType(type) && ReflectionHelper.IsConstructedFromGenericTypeDefinition(type, typeof(Code <>)), NativeType = type, IsNestedType = typeAttribute.IsNestedType, _mappingInitializer = () => inspectProperties(type, fhirVersion) }; return(true); }