Setting ExcelFunctionAttributes at runtime

Apr 30, 2009 at 12:07 PM
Hi Govert,

When registering functions in a .NET assembly, is it possible to override the default attributes applied to a function?

With our progreess so far, we have been able to prevent the functions from automatically registering by placing them in a Friend class and calling:

        Dim methods As New Generic.List(Of MethodInfo)
        Dim info As MethodInfo = GetType(HelloWorld).GetMethod("HelloWorld", New Type() {})
        methods.Add(info)
        Integration.RegisterMethods(methods)

however, changing the custom attributes before calling RegisterMethods seems to have no effect:

      Dim ma As Object() = info.GetCustomAttributes(False)
      If ma.Count > 0 Then
      With CType(ma(0), ExcelDna.Integration.ExcelFunctionAttribute)
          .Category = "My Custom Category"
          .Description = "My Custom Description"
          .Name = "My Custom Name"
       End With
     End If

Is what we are trying to acheive possible?

Thanks, Simon
Coordinator
May 4, 2009 at 10:12 AM
Hi Simon,

I don't think you can edit the attributes on a method this way. The attributes are baked in when the assembly is created, and I think if you made a call to GetCustomAttributes after the changes you make, you get back the unchanged attributes.

The long term answer is probably to have be a more flexible registration plan for ExcelDna, which is on the cards, but you shouldn't hold your breath :-(

Maybe there's another plan, if you explain a bit more of your use case.

Regards,
Govert