Example #1
0
 T IDeserializer <T> .Deserialize(IDeserializer context, ICfgNode cfgNode)
 {
     return(new T()
     {
         F1 = context.Deserialize <string>(cfgNode.NestedByName("F1").FirstOrDefault()) + "attr",
         F2 = context.Deserialize <int>(cfgNode.NestedByName("F2").FirstOrDefault()) + 10
     });
 }
Example #2
0
        internal static List <T> ToList <T>(IDeserializer context, string name, ICfgNode node)
        {
            int i = 0;

            try
            {
                List <T> result = new List <T>();
                foreach (var chItem in node.NestedByName(name))
                {
                    result.Add(context.Deserialize <T>(context, chItem));
                    i++;
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new DeserializeChildException(string.Format("{0}[{1}]", name, i), ex);
            }
        }
Example #3
0
        internal static T CustomField <T>(IDeserializer context, IDeserializer <T> custom, string name, ICfgNode node, bool required)
        {
            try
            {
                var field = node.NestedByName(name).FirstOrDefault();
                if (field == null)
                {
                    if (required)
                    {
                        throw new FormatException("field not found");
                    }
                    else
                    {
                        return(default(T));
                    }
                }

                return(custom.Deserialize(context, field));
            }
            catch (Exception ex)
            {
                throw new DeserializeChildException(name, ex);
            }
        }