コード例 #1
0
        public static void InvokeMethodValueByAttributeNameWithParameter(string functionName, string conditionString, string className, string assemblyName, ICollection <ExchangeRate> exchangeRateList)
        {
            Assembly assembly = GetAssemblyByAssemblyName(assemblyName);
            var      instance = GetInstenceByClassName(className, assembly);
            Type     type     = instance.GetType();

            MethodInfo[] methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach (var method in methodInfo)
            {
                object[] attributes = method.GetCustomAttributes(typeof(ConditionAttribute), true);
                object[] obj        = new object[1];
                obj[0] = exchangeRateList;
                foreach (var item in attributes)
                {
                    ConditionAttribute attr = item as ConditionAttribute;
                    if (null != attr)
                    {
                        if (attr.FunctionName == functionName && attr.ConditionString == conditionString)
                        {
                            type.GetMethod(method.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Invoke(instance, obj);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static void InvokeMethodValueByAttributeName(string functionName, string conditionString, object instance)
        {
            Type type = instance.GetType();

            MethodInfo[] methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach (var method in methodInfo)
            {
                object[] attributes = method.GetCustomAttributes(typeof(ConditionAttribute), true);
                foreach (var item in attributes)
                {
                    ConditionAttribute attr = item as ConditionAttribute;
                    if (null != attr)
                    {
                        if (attr.FunctionName == functionName && attr.ConditionString == conditionString)
                        {
                            type.GetMethod(method.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Invoke(instance, null);
                        }
                    }
                }
            }
        }