Exemplo n.º 1
0
        public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
        {
            Array result = Array.CreateInstance(EnumType, 0);

            object value;

            string[] values = ConverCore.GetValues(data, key, prefix);
            if (values != null)
            {
                result = Array.CreateInstance(EnumType, values.Length);
                for (int i = 0; i < values.Length; i++)
                {
                    if (string.IsNullOrEmpty(values[i]))
                    {
                        result.SetValue(Enum.GetValues(EnumType).GetValue(0), i);
                    }
                    else
                    {
                        result.SetValue(Enum.Parse(EnumType, values[i]), i);
                    }
                }
            }
            succeed = true;
            return(result);
        }
Exemplo n.º 2
0
        public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
        {
            string input  = ConverCore.GetValue(data, key, prefix);
            Int16  result = 0;

            succeed = Int16.TryParse(input, out result);
            return(result);
        }
Exemplo n.º 3
0
 public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
 {
     string[] values = ConverCore.GetValues(data, key, prefix);
     succeed = true;
     if (values == null)
     {
         values = new string[0];
     }
     return(values);
 }
Exemplo n.º 4
0
        private bool GetClassValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value)
        {
            IConvert convert = null;

            value = null;
            Type createtype = Info.ParameterType;

            if (Binder != null && Binder.Convert == null && Binder.Fungible != null)
            {
                createtype = Binder.Fungible;
            }
            bool succed = false;

            if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix))
            {
                Prefix = Binder.Prefix;
            }
            if (Binder != null)
            {
                convert = Binder.GetConvert();
            }
            if (convert == null)
            {
                if (ConverCore.Converts.ContainsKey(createtype))
                {
                    convert = ConverCore.Converts[createtype];
                }
            }
            if (convert != null)
            {
                value = convert.Parse(data, Info.Name, Prefix, out succed);
            }
            else if (createtype.IsArray)
            {
                if (createtype.GetElementType().IsEnum)
                {
                    ToEnumArray tea = new ToEnumArray();
                    tea.EnumType = createtype.GetElementType();
                    value        = tea.Parse(data, Info.Name, Prefix, out succed);
                }
            }
            else
            {
                if (createtype.IsClass && !createtype.IsInterface &&
                    !createtype.IsAbstract)
                {
                    ClassBinder cb = ConverCore.GetBinder(createtype);
                    succed = true;
                    value  = cb.CreateObject(data, Prefix);
                }
            }

            return(succed);
        }
Exemplo n.º 5
0
        public bool GetClassValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value)
        {
            IConvert convert = null;

            value = null;
            Type createtype = Handler.Property.PropertyType;

            if (Binder != null && Binder.Convert == null && Binder.Fungible != null)
            {
                createtype = Binder.Fungible;
            }
            bool succed = false;

            if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix))
            {
                Prefix = Binder.Prefix;
            }
            if (Binder != null)
            {
                convert = Binder.GetConvert();
            }
            if (convert == null)
            {
                if (ConverCore.Converts.ContainsKey(createtype))
                {
                    convert = ConverCore.Converts[createtype];
                }
            }
            if (convert != null)
            {
                value = convert.Parse(data, Handler.Property.Name, Prefix, out succed);
            }
            else
            {
                if (createtype.IsClass && !createtype.IsInterface &&
                    !createtype.IsAbstract)
                {
                    if (createtype.IsArray)
                    {
                        succed = true;
                        value  = Activator.CreateInstance(createtype, 0);
                    }
                    else
                    {
                        ClassBinder cb = ConverCore.GetBinder(createtype);
                        succed = true;
                        value  = cb.CreateObject(data, Prefix);
                    }
                }
            }

            return(succed);
        }
Exemplo n.º 6
0
        public static object CreateInstance(Type type, NameValueCollection data, string prefix)
        {
            if (ConverCore.Converts.ContainsKey(type))
            {
                IConvert convert = ConverCore.Converts[type];
                bool     succed;
                return(convert.Parse(data, null, prefix, out succed));
            }
            ClassBinder cb = ConverCore.GetBinder(type);

            return(cb.CreateObject(data, prefix));
        }
Exemplo n.º 7
0
        public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
        {
            string input = ConverCore.GetValue(data, key, prefix);

            if (string.IsNullOrEmpty(input))
            {
                succeed = false;
            }
            else
            {
                succeed = true;
            }
            return(input);
        }
Exemplo n.º 8
0
        public static IList <ValidaterInfo> Validating(object obj, bool throwerr)
        {
            ClassBinder           cb     = ConverCore.GetBinder(obj.GetType());
            IList <ValidaterInfo> result = cb.Validating(obj);

            if (throwerr)
            {
                foreach (ValidaterInfo vi in result)
                {
                    if (vi.State == ValidaterState.Error)
                    {
                        throw new ValidaterException(vi.Message);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 9
0
        public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
        {
            T[] results = new T[0];
            T   result;

            succeed = true;
            string[] values = ConverCore.GetValues(data, key, prefix);
            succeed = (values != null && values.Length > 0);
            if (values != null)
            {
                results = new T[values.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    if (Parse(values[i], out result))
                    {
                        results[i] = result;
                    }
                }
            }

            return(results);
        }
Exemplo n.º 10
0
        public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed)
        {
            IList <T> items = null;

            succeed = true;
            System.Type itemstype = System.Type.GetType("System.Collections.Generic.List`1");
            itemstype = itemstype.MakeGenericType(typeof(T));
            items     = (IList <T>)Activator.CreateInstance(itemstype);
            int count = 0;

            string[] values;
            Dictionary <System.Reflection.PropertyInfo, string[]> valueCollection = new Dictionary <System.Reflection.PropertyInfo, string[]>();

            foreach (System.Reflection.PropertyInfo pi in Properties)
            {
                values = ConverCore.GetValues(data, pi.Name, prefix);
                if (values != null && values.Length > count)
                {
                    count = values.Length;
                }
                valueCollection.Add(pi, values);
            }

            for (int i = 0; i < count; i++)
            {
                System.Collections.Specialized.NameValueCollection itemdata = new System.Collections.Specialized.NameValueCollection();
                foreach (System.Reflection.PropertyInfo pi in Properties)
                {
                    values = valueCollection[pi];
                    if (values != null && i < values.Length)
                    {
                        itemdata.Add(pi.Name, values[i]);
                    }
                }
                T item = BinderAdapter.CreateInstance <T>(itemdata);
                items.Add(item);
            }
            return(items);
        }
Exemplo n.º 11
0
        public static IList <ValidaterInfo> Validating(object obj)
        {
            ClassBinder cb = ConverCore.GetBinder(obj.GetType());

            return(cb.Validating(obj));
        }
Exemplo n.º 12
0
 public static void AddCustomConvert(params Assembly[] assemblies)
 {
     ConverCore.AddCustomConvert(assemblies);
 }
Exemplo n.º 13
0
        public static void Full(object obj, NameValueCollection data, string prefix, bool ispostback)
        {
            ClassBinder cb = ConverCore.GetBinder(obj.GetType());

            cb.FullData(obj, data, prefix, ispostback);
        }