Generally speaking, it would be better to build a delegate for access in the same place where you check that the method exists. More precisely, the process of building such a delegate itself would be such a check:
class SomeClass<T> { static readonly Action<T> SomeMethodInvoker; static SomeClass() { var p = Expression.Parameter(typeof(T)); // Π‘ΡΡΠΎΠΊΠ° Π½ΠΈΠΆΠ΅ ΠΊΠΈΠ½Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π΅ΡΠ»ΠΈ ΠΌΠ΅ΡΠΎΠ΄ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½ var body = Expression.Call(p, "SomeMethod", null); SomeMethodInvoker = Expression.Labmda<Action<T>>(body, p).Compile(); } void Foo(T a) { SomeMethodInvoker(a); } }
But if you are too lazy to write so much code, you can use dynamic . Inside it has all the same construction of the expression and its compilation, only with add. checks:
class SomeClass<T> { void Foo(T a) { ((dynamic)a).SomeMethod(); } }