dimanche 15 février 2015

Implement extension Method C#

I need to implement this method :Reflectable reflect<T>(IEnumerable<T> src) but i'm having troubles to get the expected output. Hope someone can help me thanks.


Here the interface Reflectable:


interface Reflectable : IEnumerable<string> { Reflectable Prop(string propName);}


and the expected Output:



IEnumerable<Student> stds = //Students
IEnumerable<String> r1 = reflect(stds).Prop("Id");
IEnumerable<String> r2 = reflect(stds).Prop("Name").Prop("Id").Prop("Age");
IEnumerable<String> r3 = reflect(stds);
r1.ToList().ForEach(Console.Write); // {3213}{3124}{35454}...
r2.ToList().ForEach(Console.Write); // {Jose, 3213, 89}{Maria, 3124, 34}{Prominencia, 35454, 23}...
r3.ToList().ForEach(Console.Write); // {}{}{}...





Aucun commentaire:

Enregistrer un commentaire