Timeline for Passing in method as func and using dynamic to circumvent type checking
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 16 at 23:20 | vote | accept | xtreampb | ||
May 15 at 22:50 | comment | added | xtreampb |
sure I could use reflection, but does it give me any meaningful type safety than if I just use dynamic. I guess it would ensure that the Invoke method exists, but at this point is it meaningful, or worth the cost of having to reflect all the different types of Func<,> with my custom types as well. this code review was mainly to ask if my policy of "no out of process calls in a component, only on pages" was okay if it forced me to write code like this.
|
|
May 15 at 22:14 | comment | added | iSR5 |
you can use type testing. if(method is Func<Task> func) and if(method is Func<MyType, Task> func) or you could just use reflection to cover all Func<,> .
|
|
May 15 at 20:10 | answer | added | J_H | timeline score: 2 | |
May 15 at 19:19 | history | edited | xtreampb | CC BY-SA 4.0 |
removed typo
|
May 15 at 19:11 | comment | added | xtreampb |
the methods being sent are always Func<Task> but are sometimes Func<MyType, Task> so that's why it's a dynamic and not a particular Func implementation.
|
|
May 15 at 19:01 | comment | added | iSR5 |
you could simply try cast dynamic to Func<Task> , you could also use generics to do a method extension so it can be reused across project.
|
|
May 15 at 18:09 | history | edited | xtreampb | CC BY-SA 4.0 |
formatting for readability
|
May 15 at 18:01 | history | edited | toolic | CC BY-SA 4.0 |
edited body
|
S May 15 at 17:57 | review | First questions | |||
May 15 at 18:01 | |||||
S May 15 at 17:57 | history | asked | xtreampb | CC BY-SA 4.0 |