コード例 #1
0
        public bool Map(object parentObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper)
        {
            var collectionElement = element.GetElementNamed(ElementName ?? destinationProperty.Name);

            if (collectionElement == null)
            {
                return false;
            }

            object destinationCollection = GetDestinationCollection(parentObject, destinationProperty);

            Action<object> adder = GetCollectionAdder(destinationCollection);
            var payloadType = destinationProperty.PropertyType.GetGenericArguments()[0];

            if (payloadType.IsComplex())
            {
                PopulateComplexValues(collectionElement, payloadType, mapper, adder);
            }
            else
            {
                PopulateSimpleValues(collectionElement, payloadType, mapper, adder);
            }

            return true;
        }
コード例 #2
0
        public bool Map(object destinationObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper)
        {
            var childElement = element.GetElementNamed(ElementName ?? destinationProperty.Name);

            if (childElement == null)
            {
                return false;
            }

            var elementValue = childElement.InnerText;

            var destinationPropertyType = destinationProperty.PropertyType;

            if (destinationPropertyType.IsEnum)
            {
                var value = Enum.Parse(destinationPropertyType, elementValue);
                destinationProperty.SetValue(destinationObject, value, null);
                return true;
            }

            if (destinationPropertyType.IsNullable())
            {
                if (elementValue == "")
                {
                    destinationProperty.SetValue(destinationObject, null, null);
                    return true;
                }

                destinationPropertyType = destinationPropertyType.GetGenericArguments()[0];
            }

            if (destinationPropertyType.IsA<IConvertible>())
            {
                var value = Convert.ChangeType(elementValue, destinationPropertyType);
                destinationProperty.SetValue(destinationObject, value, null);
                return true;
            }

            var converter = TypeDescriptor.GetConverter(destinationPropertyType);

            if (converter.CanConvertFrom(typeof (string)))
            {
                var value = converter.ConvertFromString(elementValue);
                destinationProperty.SetValue(destinationObject, value, null);
                return true;
            }

            return false;
        }
コード例 #3
0
        public bool Map(object parentObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper)
        {
            var objectElement = element.GetElementNamed(ElementName ?? destinationProperty.Name);

            if (objectElement == null)
            {
                return false;
            }

            object destinationObject = GetDestinationObject(parentObject, destinationProperty);

            /////////not sure about this....
            mapper.PopulateObject(destinationObject, objectElement);

            return true;
        }