コード例 #1
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        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 Exception("无法找到类型'" + type.FullName + "'的public的可读的索引器[" + tmp + "].");
                }
                return;
            }
            invoker.IndexerSet(obj, value, indexerParameters);
        }
コード例 #2
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        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));
        }
コード例 #3
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        public static bool ExistPropertyGet(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.ExistPropertyOrIndexerGet(propertyName));
        }
コード例 #4
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        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 Exception("无法找到类型'" + type.FullName + "'的公开实例属性" + propertyName + ".");
            }
            return(rst);
        }
コード例 #5
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        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 Exception("无法找到类型'" + type.FullName + "'的公开实例属性" + propertyName + ".");
                }
                return;
            }
            invoker.PropertySet(obj, propertyName, value);
        }
コード例 #6
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        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 Exception("无法找到类型'" + type.FullName + "'中参数为'" + tmp + "'的public索引器.");
            }
            return(rst);
        }
コード例 #7
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        public static string GetPropertyNameIgnoreCase(Type type, string propertyName)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.GetPropertyNameIgnoreCase(propertyName));
        }
コード例 #8
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        public static object MethodInvoke(Type type, object obj, string methodName, params object[] parameters)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.MethodInvoke(obj, methodName, parameters));
        }
コード例 #9
0
ファイル: Invoker.cs プロジェクト: sanlonezhang/ql
        public static object CreateInstance(Type type, params object[] parameters)
        {
            IInvoke invoker = InvokerFactory.GetInvoker(type);

            return(invoker.CreateInstance(parameters));
        }