How to write extension methods for anonymous types?
In my Previous post i have explained how to write extension method for known types.in this post am going to explain about writing extension for anonymous types
Click Here to see how to implement Extension methods in C#?
Hope this will helps you
public static class MyExtensions
{
public static T ExpectedType<T>(this IEnumerable<T> seq)
{
var type = typeof(T);
MethodInfo[] getters = type.GetProperties().Select(pi => pi.GetGetMethod()).ToArray();
var args = new object[0];
foreach (var item in seq)
{
for (int i = 0; i < getters.Length; i++)
{
//
Object value = getters[i].Invoke(item, args);
var str = value.ToString();
// you can write your code here
}
}return T;
}
}
Click Here to see how to implement Extension methods in C#?
Hope this will helps you
Labels:
C#