Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding GetExcelFunctions filter condition to include both ExcelFunctionAttribute and ExcelFunctionDocsAttribute ? #33

Open
casbby opened this issue Oct 31, 2021 · 1 comment

Comments

@casbby
Copy link

casbby commented Oct 31, 2021

Hi

I raised a issue for a conflict between ExcelFunction and ExcelFunctionDoc attribute as both of them include the same property ExplicitRegistration
Excel-DNA/ExcelDnaDoc#36

My goal is to use the Registration so I can have default parameter value. However in the Registration.CS the following function
stipulates only function with ExcelFunction attribute will be registered. This seems to be a catch 22 situation for me. I am not if this is a real oversight. And if it indeed is do you want to fix here or in the doc gen solution ( which can not support both attribute at the same time otherwise it will fail with System.Reflection.AmbiguousMatchException)

        public static IEnumerable<ExcelFunctionRegistration> GetExcelFunctions()
        {
            return from ass in ExcelIntegration.GetExportedAssemblies()
                   from typ in ass.GetTypes()
                   from mi in typ.GetMethods(BindingFlags.Public | BindingFlags.Static)
                   where mi.GetCustomAttribute<ExcelFunctionAttribute>() != null
                   select new ExcelFunctionRegistration(mi);
        }

Thank you very much
casbby

@govert
Copy link
Member

govert commented Nov 1, 2021

I still need to update the ExcelDnaDoc library, as you point out.

But for getting all the eligible functions from the Registration utility, I think you can just make your own function that enumerates them.

        public static IEnumerable<ExcelFunctionRegistration> GetExcelFunctions()
        {
            return from ass in ExcelIntegration.GetExportedAssemblies()
                   from typ in ass.GetTypes()
                   from mi in typ.GetMethods(BindingFlags.Public | BindingFlags.Static)
                   where mi.GetCustomAttribute<ExcelFunctionAttribute>() != null ||
                       mi.GetCustomAttribute<ExcelFunctionDocAttribute>() != null 
                   select new ExcelFunctionRegistration(mi);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants