Ejemplo n.º 1
0
        public JsonHelper(IDictionary <string, JsonValue> template)
        {
            CustomTypeHelper <T> .ClearProperties();

            _keys = (from k in template.Keys select k).ToArray();

            foreach (var key in template.Keys)
            {
                int    integerTest;
                double doubleTest;
                var    value = template[key].ToString();
                if (int.TryParse(value, out integerTest))
                {
                    CustomTypeHelper <T> .AddProperty(key, typeof(int));

                    _converters.Add(key, obj => int.Parse(obj.ToString()));
                }
                else if (double.TryParse(value, out doubleTest))
                {
                    CustomTypeHelper <T> .AddProperty(key, typeof(double));

                    _converters.Add(key, obj => double.Parse(obj.ToString()));
                }
                else
                {
                    CustomTypeHelper <T> .AddProperty(key, typeof(string));

                    _converters.Add(key, obj =>
                    {
                        // strip quotes
                        var str = obj.ToString().Substring(1);
                        return(str.Substring(0, str.Length - 1));
                    });
                }
            }
        }
Ejemplo n.º 2
0
 public static void AddProperty(String name, Type propertyType, List <Attribute> attributes)
 {
     CustomTypeHelper <CustomType> .AddProperty(name, propertyType, attributes);
 }
Ejemplo n.º 3
0
 public static void AddProperty(String name, Type propertyType)
 {
     CustomTypeHelper <CustomType> .AddProperty(name, propertyType);
 }