예제 #1
0
        /// <summary>
        /// Enumerate this class' properties using reflection, create PropertyMappings
        /// for them and add them to the PropertyMappings.
        /// </summary>
        private static void inspectProperties(ClassMapping me)
        {
            foreach (var property in ReflectionHelper.FindPublicProperties(me.NativeType))
            {
                // Skip properties that are marked as NotMapped
                if (ReflectionHelper.GetAttribute <NotMappedAttribute>(property) != null)
                {
                    continue;
                }

                var propMapping = PropertyMapping.Create(property);
                var propKey     = propMapping.Name.ToUpperInvariant();

                if (me._propMappings.ContainsKey(propKey))
                {
                    throw Error.InvalidOperation($"Class has multiple properties that are named '{propKey}'. The property name must be unique");
                }

                me._propMappings.Add(propKey, propMapping);

                // Keep a pointer to this property if this is a primitive value element ("Value" in primitive types)
                if (propMapping.RepresentsValueElement)
                {
                    me.PrimitiveValueProperty = propMapping;
                }
            }

            me._orderedMappings = me._propMappings.Values.OrderBy(prop => prop.Order).ToList();
        }
예제 #2
0
        /// <summary>
        /// Enumerate this class' properties using reflection, create PropertyMappings
        /// for them and add them to the PropertyMappings.
        /// </summary>
        private static PropertyMappingCollection inspectProperties(Type nativeType, FhirRelease fhirVersion)
        {
            var byName = new Dictionary <string, PropertyMapping>();

            foreach (var property in ReflectionHelper.FindPublicProperties(nativeType))
            {
                if (!PropertyMapping.TryCreate(property, out var propMapping, fhirVersion))
                {
                    continue;
                }

                var propKey = propMapping.Name.ToUpperInvariant();

                if (byName.ContainsKey(propKey))
                {
                    throw Error.InvalidOperation($"Class has multiple properties that are named '{propKey}'. The property name must be unique");
                }

                byName.Add(propKey, propMapping);
            }

            var ordered = byName.Values.OrderBy(pm => pm.Order).ToList();

            return(new PropertyMappingCollection(byName, ordered));
        }
예제 #3
0
        /// <summary>
        /// Enumerate this class' properties using reflection, create PropertyMappings
        /// for them and add them to the PropertyMappings.
        /// </summary>
        private void inspectProperties(string fhirVersion)
        {
            foreach (var property in ReflectionHelper.FindPublicProperties(NativeType))
            {
                if (!PropertyMapping.TryCreate(property, out var propMapping, fhirVersion))
                {
                    continue;
                }

                var propKey = propMapping.Name.ToUpperInvariant();

                if (_propMappings.ContainsKey(propKey))
                {
                    throw Error.InvalidOperation($"Class has multiple properties that are named '{propKey}'. The property name must be unique");
                }

                _propMappings.Add(propKey, propMapping);

                // Keep a pointer to this property if this is a primitive value element ("Value" in primitive types)
                if (propMapping.RepresentsValueElement)
                {
                    PrimitiveValueProperty = propMapping;
                }
            }

            PropertyMappings = _propMappings.Values.OrderBy(prop => prop.Order).ToList();
        }
예제 #4
0
        public ReflectedType(Type typeToReflect)
        {
            Reflected = typeToReflect ?? throw new ArgumentNullException(nameof(typeToReflect));

            _attributes       = new Lazy <IReadOnlyCollection <Attribute> >(getAttributes);
            _properties       = new Lazy <IReadOnlyCollection <ReflectedProperty> >(getProperties);
            _propertiesByName = new Lazy <IReadOnlyDictionary <string, ReflectedProperty> >(() => getPropertiesByName(_properties));

            List <Attribute> getAttributes() => ReflectionHelper.GetAttributes(Reflected).ToList();
            List <ReflectedProperty> getProperties() =>
            ReflectionHelper
            .FindPublicProperties(Reflected)
            .Select(pi => new ReflectedProperty(pi))
            .ToList();
            Dictionary <string, ReflectedProperty> getPropertiesByName(Lazy <IReadOnlyCollection <ReflectedProperty> > props) =>
            props.Value.ToDictionary(rp => rp.Name);
        }
예제 #5
0
        /// <summary>
        /// Enumerate this class' properties using reflection, create PropertyMappings
        /// for them and add them to the PropertyMappings.
        /// </summary>
        private static void inspectProperties(ClassMapping me)
        {
            foreach (var property in ReflectionHelper.FindPublicProperties(me.NativeType))
            {
                // Skip properties that are marked as NotMapped
                if (ReflectionHelper.GetAttribute <NotMappedAttribute>(property) != null)
                {
                    continue;
                }

                var propMapping = PropertyMapping.Create(property);

                me._propMappings.Add(propMapping.Name.ToUpperInvariant(), propMapping);

                // Keep a pointer to this property if this is a primitive value element ("Value" in primitive types)
                if (propMapping.RepresentsValueElement)
                {
                    me.PrimitiveValueProperty = propMapping;
                }
            }

            me._orderedMappings = me._propMappings.Values.OrderBy(prop => prop.Order).ToList();
        }