mardi 7 juillet 2020

Operator 'is' and 'as' reflection

Is there any way somehow use operators is and as except their basic use (variable is/as constantType)? You can't overload it and it seems like there is no method like op_Isinst (as there is op_Addition for +). Is the only way to somehow use it is via IL generation? For example:

public static void AddIsToILGenerator<Type>(ILGenerator ilGenerator)
{
    ilGenerator.Emit(OpCodes.Isinst, typeof(Type));
}

I do know that you don't actually need such functionality and there are functions that do the same job, I'm just curious.





Aucun commentaire:

Enregistrer un commentaire