Open sandboxFocus

Method ToMethodBase

ToMethodBase()

Gets a MethodBase that represents the current method or constructor at run time.

Declaration
MethodBase ToMethodBase()
Returns
Type Description
MethodBase

A MethodBase that can be used only in run-time code.

Remarks

This method generates run-time code that retrieves the MethodBase object (either MethodInfo or ConstructorInfo) for the current method or constructor. For more specific return types, use ToMethodInfo() or ToConstructorInfo().

While Metalama is designed to eliminate the need for reflection in most scenarios, this method is useful when you need to pass method metadata to APIs that require MethodBase objects.

Warning: The code generated by this method relies on method names and signatures, and may break if your project is obfuscated. Consider using method invokers (see IMethod.Invoke) when possible, as this approach is obfuscation-safe.

See Also