Пример #1
0
        /// <summary>
        /// Gets the binding kind of a property type.
        /// </summary>
        public static BindingMode GetBindingMode(ref Type type, out bool isNullable)
        {
            if (TypeHelper.IsScalarType(type))
            {
                isNullable = type == typeof(string);
                return(BindingMode.Scalar);
            }

            isNullable = true;

            if (type.IsGenericType && type.GetGenericArguments().Length == 1)
            {
                var gdef  = type.GetGenericTypeDefinition();
                var gtype = type.GetGenericArguments()[0];

                if (gdef == typeof(Nullable <>))
                {
                    if (TypeHelper.IsScalarType(gtype))
                    {
                        type = gtype;
                        return(BindingMode.Scalar);
                    }
                }
                else if (TypeHelper.IsGenericList(gdef))
                {
                    type = gtype;
                    if (GetBindingMode(ref gtype, out _) == BindingMode.Class)
                    {
                        return(BindingMode.ClassList);
                    }

                    return(BindingMode.List);
                }
            }

            if (TypeHelper.IsDictionary(type))
            {
                return(BindingMode.Dictionary);
            }

            if (type.IsClass && !type.IsInterface)
            {
                return(BindingMode.Class);
            }

            return(BindingMode.None);
        }