Skip to content Skip to sidebar Skip to footer

Python For .net: How To Call A Method Of A Static Class Using Reflection?

I want to use a method of a static class. This is my C# code: namespace SomeNamepace { public struct SomeStruct { .... } public static class SomeClass

Solution 1:

Thanks to the comments to the question I was able to find a solution using MethodBase.Invoke (Object, Object[])

lib = clr.AddReference('c:\\Test\Module.dll')
from System import Type
my_type = lib.GetType('SomeNamespace.SomeClass')
method = my_type.GetMethod('SomeMethod')  

# RetType is void in my case, so None works
RetType = None
# parameters passed to the functions need to be a list
method.Invoke(RetType, [param1, param2])  

Post a Comment for "Python For .net: How To Call A Method Of A Static Class Using Reflection?"