How does the is
operator work with respect to the DLR?
To make my question a little more explicit, consider the following signature:
public bool Is<T>(Func<dynamic> getInstance)
{
return getInstance() is T;
}
By default, what conditions are necessary for Is<T>
to return true
? Furthermore, does the DLR provide any mechanism to customize this behavior?
At runtime, dynamic
is treated the same as object
, which means that the runtime type of the getInstance
delegate's result will be used to perform this check. The only difference using dynamic
here will cause is that there will be no compile time checking, and dynamic binding will be used at runtime to perform this check on the dynamic object returned by getInstance
.
By default, what conditions are necessary for Is to return true?
The delegate passed in will need to return a type which, at runtime, is compatible with T
.
Furthermore, does the DLR provide any mechanism to customize this behavior?
No. This is going to use the standard rules for C# types. Any custom behavior would need to be written into the logic itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With