c# - Detecting dynamic parameters and return types -
I have seen the entire stack overflow but have not yet found the solution. How can I use reflection to differentiate between dynamic
and object
parameters and returns types? For example, suppose I have many methods in the class like this:
Public Zero Foo (Dynamic D) {} Public Zero Times (Object O) {} Public Dynamic Foo ( ) {Return "foo"; } Public object bar () {return "bar"; }
How do I get names of Foo
and times
's?
dynamic
parameter, return type or members, which you can find out. For the sake of summarizing, you can define a supporting method like this: Fixed bool isDynamic (ParameterInfo PI) {return pi.GetCustomAttributes, true). Langs & gt; 0; }
or if you are using .NET 4.5 or later, then you can extensively expand methods from the helper class:
Fixed bool isDynamic (ParameterInfo pi) {return pi.IsDefined (typeof (DynamicAttribute)); }
Then you can find those methods that either select a dynamic type or return it:
dynamicMethods = myType. GetMethods () Mi = & gt; IsDynamic (mi.ReturnParameter) || Mi.GetParameters (). IsDynamic);
Note that if you try to use DynamicAttribute
directly, the C # compiler will throw an error, but other CIL compiler Could.
Comments
Post a Comment