Esempio n. 1
0
        public static void IndexerSet(Type type, object obj, object value, bool throwOnPropertyNotExist, params object[] indexerParameters)
        {
            if (indexerParameters == null || indexerParameters.Length <= 0)
            {
                throw new ArgumentException("索引器必须要有参数.", "indexerParamTypes");
            }
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            Type[] indexerParamTypes = new Type[indexerParameters.Length];
            for (int i = 0; i < indexerParameters.Length; i++)
            {
                indexerParamTypes[i] = indexerParameters[i].GetType();
            }
            if (!ExistIndexerSet(type, indexerParamTypes))
            {
                if (throwOnPropertyNotExist)
                {
                    string tmp = string.Empty;
                    foreach (Type t in indexerParamTypes)
                    {
                        if (tmp.Length > 0)
                        {
                            tmp += ", ";
                        }
                        tmp += t.FullName;
                    }
                    throw new ApplicationException("无法找到类型'" + type.FullName + "'的public的可读的索引器[" + tmp + "].");
                }
                return;
            }
            invoker.IndexerSet(obj, value, indexerParameters);
        }
Esempio n. 2
0
        public static bool ExistIndexerSet(Type type, params Type[] indexerParamTypes)
        {
            if (indexerParamTypes == null || indexerParamTypes.Length <= 0)
            {
                throw new ArgumentException("索引器必须要有参数.", "indexerParamTypes");
            }
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.ExistPropertyOrIndexerSet("Item", indexerParamTypes));
        }
Esempio n. 3
0
        public static bool ExistPropertySet(Type type, string propertyName, bool ignoreCase)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            if (ignoreCase)
            {
                propertyName = GetPropertyNameIgnoreCase(type, propertyName);
            }
            if (propertyName == null || propertyName.Trim().Length <= 0 || propertyName == "Item")
            {
                return(false);
            }
            return(invoker.ExistPropertyOrIndexerSet(propertyName));
        }
Esempio n. 4
0
        public static Type GetPropertyType(Type type, string propertyName, bool ignoreCase, bool throwOnPropertyNotExist)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            if (ignoreCase)
            {
                propertyName = GetPropertyNameIgnoreCase(type, propertyName);
            }
            Type rst = (propertyName == null || propertyName.Trim().Length <= 0) ? null : invoker.GetPropertyType(propertyName);

            if (rst == null && throwOnPropertyNotExist)
            {
                throw new ApplicationException("无法找到类型'" + type.FullName + "'的公开实例属性" + propertyName + ".");
            }
            return(rst);
        }
Esempio n. 5
0
        public static void PropertySet(Type type, object obj, string propertyName, object value, bool ignoreCase, bool throwOnPropertyNotExist)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            if (ignoreCase)
            {
                propertyName = GetPropertyNameIgnoreCase(type, propertyName);
            }
            if (propertyName == null || propertyName.Trim().Length <= 0 || !ExistPropertySet(type, propertyName))
            {
                if (throwOnPropertyNotExist)
                {
                    throw new ApplicationException("无法找到类型'" + type.FullName + "'的公开实例属性" + propertyName + ".");
                }
                return;
            }
            invoker.PropertySet(obj, propertyName, value);
        }
Esempio n. 6
0
        public static Type GetIndexerType(Type type, bool throwOnIndexerNotExist, params Type[] indexerParamTypes)
        {
            if (indexerParamTypes == null || indexerParamTypes.Length <= 0)
            {
                throw new ArgumentException("索引器必须要有参数.", "indexerParamTypes");
            }
            IInvoke invoker = InvokerFactory.GetInvoker(type);
            Type    rst     = invoker.GetIndexerType(indexerParamTypes);

            if (rst == null && throwOnIndexerNotExist)
            {
                string tmp = string.Empty;
                foreach (Type t in indexerParamTypes)
                {
                    if (tmp.Length > 0)
                    {
                        tmp += ", ";
                    }
                    tmp += t.FullName;
                }
                throw new ApplicationException("无法找到类型'" + type.FullName + "'中参数为'" + tmp + "'的public索引器.");
            }
            return(rst);
        }
Esempio n. 7
0
        public static string GetPropertyNameIgnoreCase(Type type, string propertyName)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.GetPropertyNameIgnoreCase(propertyName));
        }
Esempio n. 8
0
        public static object MethodInvoke(Type type, object obj, string methodName, params object[] parameters)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.MethodInvoke(obj, methodName, parameters));
        }
Esempio n. 9
0
        public static object CreateInstance(Type type, params object[] parameters)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.CreateInstance(parameters));
        }