Example #1
0
        private static bool ReadValue(IScope scope, IReader reader, object obj, IElementDef def, IPropertyDef property, out object value)
        {
            var type = property.Type;

            if (type == typeof(object))
            {
                value = reader.ReadObject();
                return(true);
            }

            if (scope.TryRead(() => reader.ReadString(), type, out value))
            {
                return(true);
            }

            var xmlReader = reader as XmlReaderImpl;

            if (xmlReader != null)
            {
                var surrogate = scope.GetSurrogate(type);
                if (surrogate != null)
                {
                    value = CreateElement(property, obj);
                    surrogate.Read(xmlReader.XmlReader, value);
                    return(true);
                }
            }

            var elementDef = scope.GetElementDef(type);

            if (elementDef != null)
            {
                var subScope = elementDef as IScope;
                value = ReadElement(subScope ?? scope, reader, elementDef, () => CreateElement(property, obj));
                return(true);
            }

            if (ReadEnumElement(reader, type, out value))
            {
                return(true);
            }

            // try read collection
            var elementType = Reflector.GetItemType(type);

            if (elementType != null)
            {
                elementDef = new CollectionDef(scope, property.Name, type, elementType);
                value      = def.IsImmutable ? CreateList(elementType) : CreateElement(property, obj);
                ReadElement(scope, reader, elementDef, value);
                return(true);
            }

            value = null;
            return(false);
        }
Example #2
0
 public ItemDefCollection(CollectionDef collectionDef)
 {
     _collectionDef = collectionDef;
 }
Example #3
0
 public ItemDef(CollectionDef collectionDef, XName name)
 {
     _collectionDef = collectionDef;
     Name           = name;
     ItemName       = name;
 }
Example #4
0
        private static bool ReadValue(IScope scope, IReader reader, object obj, IElementDef def, IPropertyDef property, out object value)
        {
            var type = property.Type;

            if (type == typeof(object))
            {
                value = reader.ReadObject();
                return true;
            }

            if (scope.TryRead(() => reader.ReadString(), type, out value))
                return true;

            var xmlReader = reader as XmlReaderImpl;
            if (xmlReader != null)
            {
                var surrogate = scope.GetSurrogate(type);
                if (surrogate != null)
                {
                    value = CreateElement(property, obj);
                    surrogate.Read(xmlReader.XmlReader, value);
                    return true;
                }
            }

            var elementDef = scope.GetElementDef(type);
            if (elementDef != null)
            {
                var subScope = elementDef as IScope;
                value = ReadElement(subScope ?? scope, reader, elementDef, () => CreateElement(property, obj));
                return true;
            }

            if (ReadEnumElement(reader, type, out value))
                return true;

            // try read collection
            var elementType = Reflector.GetItemType(type);
            if (elementType != null)
            {
                elementDef = new CollectionDef(scope, property.Name, type, elementType);
                value = def.IsImmutable ? CreateList(elementType) : CreateElement(property, obj);
                ReadElement(scope, reader, elementDef, value);
                return true;
            }

            value = null;
            return false;
        }