コード例 #1
0
    private bool IsPolymorphic(string name)
    {
        var mappedProperty = m_mapping.FindMappedElementByName(name);

        if (mappedProperty != null)
        {
            return(mappedProperty.Choice == ChoiceType.DatatypeChoice);
        }
        return(false);
    }
コード例 #2
0
 private bool IsPolymorphic()
 {
     if (m_reader.TokenType == JsonToken.PropertyName)
     {
         var mappedProperty = m_mapping.FindMappedElementByName(m_reader.Value as string);
         if (mappedProperty != null)
         {
             return(mappedProperty.Choice == ChoiceType.DatatypeChoice);
         }
     }
     return(false);
 }
コード例 #3
0
        private void read(ClassMapping mapping, IEnumerable <Tuple <string, IFhirReader> > members, object existing)
        {
            //bool hasMember;

            foreach (var memberData in members)
            {
                //hasMember = true;
                var memberName = memberData.Item1;  // tuple: first is name of member

                // Find a property on the instance that matches the element found in the data
                // NB: This function knows how to handle suffixed names (e.g. xxxxBoolean) (for choice types).
                var mappedProperty = mapping.FindMappedElementByName(memberName);

                if (mappedProperty != null)
                {
                    //   Message.Info("Handling member {0}.{1}", mapping.Name, memberName);

                    object value = null;

                    // For primitive members we can save time by net calling the getter
                    if (!mappedProperty.IsPrimitive)
                    {
                        value = mappedProperty.GetValue(existing);
                    }

                    var reader = new DispatchingReader(memberData.Item2);
                    value = reader.Deserialize(mappedProperty, memberName, value);

                    mappedProperty.SetValue(existing, value);
                }
                else
                {
                    if (SerializationConfig.AcceptUnknownMembers == false)
                    {
                        throw Error.Format(Messages.DeserializeUnknownMember, _current, memberName);
                    }
                    else
                    {
                        Message.Info("Skipping unknown member " + memberName);
                    }
                }
            }

            // Not sure if the reader needs to verify this. Certainly, I want to accept empty elements for the
            // pseudo-resource TagList (no tags) and probably others.
            //if (!hasMember)
            //    throw Error.Format("Fhir serialization does not allow nor support empty elements");
        }
コード例 #4
0
        public IEnumerable <ITypedElement> Children(string name)
        {
            if (!(Current is Base parentBase))
            {
                yield break;
            }

            var    children       = parentBase.NamedChildren;
            string oldElementName = null;
            int    arrayIndex     = 0;

            foreach (var child in children)
            {
                if (name == null || child.ElementName == name)
                {
                    // Poll the actual implementation, which results in a more efficient loopkup when the underlying
                    // implementation of _mySD is ClassMapping.
                    var childElementDef = _myClassMapping.FindMappedElementByName(child.ElementName);

                    if (oldElementName != child.ElementName)
                    {
                        arrayIndex = 0;
                    }
                    else
                    {
                        arrayIndex += 1;
                    }

                    var location = Location == null
                        ? child.ElementName
                        : $"{Location}.{child.ElementName}[{arrayIndex}]";
                    var shortPath = ShortPath == null
                        ? child.ElementName
                        : (childElementDef.IsCollection ?
                           $"{ShortPath}.{child.ElementName}[{arrayIndex}]" :
                           $"{ShortPath}.{child.ElementName}");

                    yield return(new PocoElementNode(_inspector, child.Value, this, childElementDef,
                                                     location, shortPath));
                }

                oldElementName = child.ElementName;
            }
        }
コード例 #5
0
        private void read(ClassMapping mapping, IEnumerable <Tuple <string, IFhirReader> > members, Base existing)
        {
            //bool hasMember;

            foreach (var memberData in members)
            {
                //hasMember = true;
                var memberName = memberData.Item1;  // tuple: first is name of member

                // Find a property on the instance that matches the element found in the data
                // NB: This function knows how to handle suffixed names (e.g. xxxxBoolean) (for choice types).
                var mappedProperty = mapping.FindMappedElementByName(memberName);

                if (mappedProperty != null)
                {
                    //   Message.Info("Handling member {0}.{1}", mapping.Name, memberName);

                    object value = null;

                    // For primitive members we can save time by not calling the getter
                    if (!mappedProperty.IsPrimitive)
                    {
                        value = mappedProperty.GetValue(existing);
                    }

                    var reader = new DispatchingReader(memberData.Item2);
                    value = reader.Deserialize(mappedProperty, memberName, value);

                    mappedProperty.SetValue(existing, value);
                }
                else
                {
                    if (SerializationConfig.AcceptUnknownMembers == false)
                    {
                        throw Error.Format("Encountered unknown member '{0}' while de-serializing", _current, memberName);
                    }
                    else
                    {
                        Message.Info("Skipping unknown member " + memberName);
                    }
                }
            }
        }
コード例 #6
0
        private void read(ClassMapping mapping, IEnumerable <Tuple <string, IFhirReader> > members, Base existing)
        {
            //bool hasMember;

            foreach (var memberData in members)
            {
                //hasMember = true;
                var memberName = memberData.Item1;  // tuple: first is name of member

                // Find a property on the instance that matches the element found in the data
                // NB: This function knows how to handle suffixed names (e.g. xxxxBoolean) (for choice types).
                var mappedProperty = mapping.FindMappedElementByName(memberName);

                if (mappedProperty != null)
                {
                    //   Message.Info("Handling member {0}.{1}", mapping.Name, memberName);

                    object value = null;

                    // For primitive members we can save time by not calling the getter
                    if (!mappedProperty.IsPrimitive)
                    {
                        value = mappedProperty.GetValue(existing);
                    }

                    var reader = new DispatchingReader(memberData.Item2, Settings, arrayMode: false);
                    value = reader.Deserialize(mappedProperty, memberName, value);

                    if (mappedProperty.RepresentsValueElement && mappedProperty.ElementType.IsEnum() && value is String)
                    {
                        if (!Settings.AllowUnrecognizedEnums)
                        {
                            if (EnumUtility.ParseLiteral((string)value, mappedProperty.ElementType) == null)
                            {
                                throw Error.Format("Literal '{0}' is not a valid value for enumeration '{1}'".FormatWith(value, mappedProperty.ElementType.Name), _current);
                            }
                        }

                        ((Primitive)existing).ObjectValue = value;
                        //var prop = ReflectionHelper.FindPublicProperty(mapping.NativeType, "RawValue");
                        //prop.SetValue(existing, value, null);
                        //mappedProperty.SetValue(existing, null);
                    }
                    else
                    {
                        mappedProperty.SetValue(existing, value);
                    }
                }
                else
                {
                    if (Settings.AcceptUnknownMembers == false)
                    {
                        throw Error.Format("Encountered unknown member '{0}' while de-serializing".FormatWith(memberName), _current);
                    }
                    else
                    {
                        Message.Info("Skipping unknown member " + memberName);
                    }
                }
            }
        }
コード例 #7
0
        //this should be refactored into read(ITypedElement parent, Base existing)

        private void read(ClassMapping mapping, IEnumerable <ITypedElement> members, Base existing)
        {
            foreach (var memberData in members)
            {
                var memberName = memberData.Name;  // tuple: first is name of member

                // Find a property on the instance that matches the element found in the data
                // NB: This function knows how to handle suffixed names (e.g. xxxxBoolean) (for choice types).
                var mappedProperty = mapping.FindMappedElementByName(memberName);

                if (mappedProperty != null)
                {
                    //   Message.Info("Handling member {0}.{1}", mapping.Name, memberName);

                    object value = null;

                    // For primitive members we can save time by not calling the getter
                    if (!mappedProperty.IsPrimitive)
                    {
                        value = mappedProperty.GetValue(existing);

                        if (value != null && !mappedProperty.IsCollection)
                        {
                            RaiseFormatError($"Element '{mappedProperty.Name}' must not repeat", memberData.Location);
                        }
                    }

                    var reader = new DispatchingReader(memberData, Settings, arrayMode: false);

                    // Since we're still using both ClassMappings and the newer IElementDefinitionSummary provider at the same time,
                    // the member might be known in the one (POCO), but unknown in the provider. This is only in theory, since the
                    // provider should provide exactly the same information as the mappings. But better to get a clear exception
                    // when this happens.
                    value = reader.Deserialize(mappedProperty, memberName, value);

                    if (mappedProperty.RepresentsValueElement && mappedProperty.ImplementingType.IsEnum() && value is String)
                    {
                        if (!Settings.AllowUnrecognizedEnums)
                        {
                            if (EnumUtility.ParseLiteral((string)value, mappedProperty.ImplementingType) == null)
                            {
                                RaiseFormatError($"Literal '{value}' is not a valid value for enumeration '{mappedProperty.ImplementingType.Name}'", _current.Location);
                            }
                        }

                        ((Primitive)existing).ObjectValue = value;
                        //var prop = ReflectionHelper.FindPublicProperty(mapping.NativeType, "RawValue");
                        //prop.SetValue(existing, value, null);
                        //mappedProperty.SetValue(existing, null);
                    }
                    else
                    {
                        mappedProperty.SetValue(existing, value);
                    }
                }
                else
                {
                    if (Settings.AcceptUnknownMembers == false)
                    {
                        RaiseFormatError($"Encountered unknown member '{memberName}' while de-serializing", memberData.Location);
                    }
                    else
                    {
                        Message.Info("Skipping unknown member " + memberName);
                    }
                }
            }
        }