ExcelDna.Loader.XlMethodInfo.GetMethodAttributes C# (CSharp) Метод

GetMethodAttributes() публичный статический Метод

public static GetMethodAttributes ( List methodInfos, List &methodAttributes, List &argumentAttributes ) : void
methodInfos List
methodAttributes List
argumentAttributes List
Результат void
        public static void GetMethodAttributes(List<MethodInfo> methodInfos, out List<object> methodAttributes, out List<List<object>> argumentAttributes)
        {
            methodAttributes = new List<object>();
            argumentAttributes = new List<List<object>>();
            foreach (MethodInfo method in methodInfos)
            {
                // If we don't find an attribute, we'll set a null in the list at a token
                methodAttributes.Add(null);
                foreach (object att in method.GetCustomAttributes(false))
                {
                    Type attType = att.GetType();
                    if (TypeHelper.TypeHasAncestorWithFullName(attType, "ExcelDna.Integration.ExcelFunctionAttribute") ||
                        TypeHelper.TypeHasAncestorWithFullName(attType, "ExcelDna.Integration.ExcelCommandAttribute"))
                    {
                        // Set last value to this attribute
                        methodAttributes[methodAttributes.Count - 1] = att;
                        break;
                    }
                    if (att is System.ComponentModel.DescriptionAttribute)
                    {
                        // Some compatibility - use Description if no Excel* attribute
                        if (methodAttributes[methodAttributes.Count - 1] == null)
                            methodAttributes[methodAttributes.Count - 1] = att;
                    }
                }

                List<object> argAttribs = new List<object>();
                argumentAttributes.Add(argAttribs);

                foreach (ParameterInfo param in method.GetParameters())
                {
                    // If we don't find an attribute, we'll set a null in the list at a token
                    argAttribs.Add(null);
                    foreach (object att in param.GetCustomAttributes(false))
                    {
                        Type attType = att.GetType();
                        if (TypeHelper.TypeHasAncestorWithFullName(attType, "ExcelDna.Integration.ExcelArgumentAttribute"))
                        {
                            // Set last value to this attribute
                            argAttribs[argAttribs.Count - 1] = att;
                            break;
                        }
                        if (att is System.ComponentModel.DescriptionAttribute)
                        {
                            // Some compatibility - use Description if no ExcelArgument attribute
                            if (argAttribs[argAttribs.Count - 1] == null)
                                argAttribs[argAttribs.Count - 1] = att;
                        }
                    }

                }
            }
        }

Usage Example

Пример #1
0
        static double registrationInfoVersion            = 0.0; // Incremented every time the registration changes, used by GetRegistrationInfo to short-circuit.

        public static void RegisterMethods(List <MethodInfo> methods)
        {
            List <object>         methodAttributes;
            List <List <object> > argumentAttributes;

            XlMethodInfo.GetMethodAttributes(methods, out methodAttributes, out argumentAttributes);
            RegisterMethodsWithAttributes(methods, methodAttributes, argumentAttributes);
        }