Static Reflection

Έχουν δημοσιευτεί 15 Ιουνίου 09 05:27 πμ | tolisss 
We all get into situation where we need to access class metadata like properties,methods and fields and we use reflection to accomplish it private class Customer { public string LastName { get; set; } } [Test] public void Test() { Assert.IsNotNull(typeof(Customer).GetProperty("LastName")); } but what will happen if we change the property name of “LastName” to “SurnName” ?? Our test will fail . But there is a rescue on this one using linq expression trees. public static class ReflectionExtensions { public static MethodInfo GetMethod<TTarget>(this TTarget target, Expression<Action<TTarget>> method) { return GetMethodInfo(method); } private static MethodInfo GetMethodInfo(Expression method) { if (method == null) throw new ArgumentNullException("method");

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: ,

Σχόλια:

Χωρίς Σχόλια
Έχει απενεργοποιηθεί η προσθήκη σχολίων από ανώνυμα μέλη

Search

Go

Το Ιστολόγιο

Ιστορικό Δημοσιεύσεων

Συνδρομές