Exemplo n.º 1
0
        public ClassContentReader(
            IContentReaderCollection contentReaderCollection,
            IXmlAttributeInterpreter xmlAttributeInterpreter,
            OnDeserializeConfiguration onDeserializeConfiguration)
        {
            this.onDeserializeConfiguration = onDeserializeConfiguration;
            emitConstruction = ReadHelpers.EmitConstruction <T>();
            var infos =
                typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);

            foreach (var propertyInfo in infos)
            {
                if (PropertyIsBad(propertyInfo))
                {
                    continue;
                }
                if (propertyInfo.IsDefined(typeof(XmlAttributeAttribute), false))
                {
                    var name = xmlAttributeInterpreter.GetXmlNodeName(propertyInfo);
                    attributeMap.Add(name, ReadHelpers.BuildSetter <T>(propertyInfo, contentReaderCollection));
                }
                else
                {
                    var name = xmlAttributeInterpreter.GetXmlNodeName(propertyInfo);
                    propertiesMap.Add(name, ReadHelpers.BuildSetter <T>(propertyInfo, contentReaderCollection));
                }
            }
        }
Exemplo n.º 2
0
        public ContentReaderCollection(IXmlAttributeInterpreter xmlAttributeInterpreter, OnDeserializeConfiguration onDeserializeConfiguration)
        {
            var leafContentReaders = new Dictionary <object, object>
            {
                { typeof(string), new StringContentReader() },
                { typeof(int), new SimpleContentReader <int>(int.TryParse) },
                { typeof(byte), new SimpleContentReader <byte>(byte.TryParse) },
                { typeof(long), new SimpleContentReader <long>(long.TryParse) },
                { typeof(bool), new SimpleContentReader <bool>(bool.TryParse) },
                { typeof(double), new FractionalContentReader <double>(double.TryParse) },
                { typeof(float), new FractionalContentReader <float>(float.TryParse) },
                { typeof(Guid), new SimpleContentReader <Guid>(Guid.TryParse) },
                { typeof(DateTime), new DateTimeContentReader() },
                { typeof(decimal), new FractionalContentReader <decimal>(decimal.TryParse) },
            };

            this.xmlAttributeInterpreter    = xmlAttributeInterpreter;
            this.onDeserializeConfiguration = onDeserializeConfiguration;
            foreach (var leafContentReader in leafContentReaders)
            {
                readers.Add(leafContentReader.Key, leafContentReader.Value);
            }
        }
 public ContentWriterCollection(IXmlAttributeInterpreter xmlAttributeInterpreter)
 {
     this.xmlAttributeInterpreter = xmlAttributeInterpreter;
 }
Exemplo n.º 4
0
 public PairContentWriter(IContentWriter keyContentWriter, IContentWriter valueContentWriter, IXmlAttributeInterpreter xmlAttributeInterpreter)
 {
     this.keyContentWriter   = keyContentWriter;
     this.valueContentWriter = valueContentWriter;
     keyNodeInfo             = xmlAttributeInterpreter.GetPropertyNodeInfo(typeof(DictionaryKeyValuePair).GetProperty("Key"));
     valueNodeInfo           = xmlAttributeInterpreter.GetPropertyNodeInfo(typeof(DictionaryKeyValuePair).GetProperty("Value"));
 }
Exemplo n.º 5
0
        public ClassContentWriter(Type type, IContentWriterCollection contentWriterCollection, IXmlAttributeInterpreter xmlAttributeInterpreter)
        {
            this.xmlAttributeInterpreter = xmlAttributeInterpreter;
            var list            = new List <IValueWriter>();
            var funcList        = new List <Func <object, object> >();
            var elementInfoList = new List <XmlElementInfo>();

            ProcessAttributes(type, funcList, list, elementInfoList, contentWriterCollection);
            ProcessOtherProps(type, funcList, list, elementInfoList, contentWriterCollection);
            writers           = list.ToArray();
            readPropertyFuncs = funcList.ToArray();
        }
Exemplo n.º 6
0
 public DictionaryValueWriter(XmlElementInfo xmlElementInfo, IContentWriter keyWriter, IContentWriter valueWriter, IXmlAttributeInterpreter xmlAttributeInterpreter)
 {
     itemContentWriter = new PairContentWriter(keyWriter, valueWriter, xmlAttributeInterpreter);
     arrayValueWriter  = new ArrayValueWriter(xmlElementInfo, itemContentWriter);
 }
 public RootContentWriter(Type type, IContentWriterCollection contentWriterCollection, IXmlAttributeInterpreter xmlAttributeInterpreter)
 {
     contentWriter   = contentWriterCollection.Get(type);
     rootElementInfo = xmlAttributeInterpreter.GetRootNodeInfo(type);
 }