jeudi 16 février 2017

Copy method signatures from content to container

I've got a class (content) that holds a data object that is searchable by several methods

    public class MyClass
    {
        public DataTable table { get; set; }

        public string GetValue(string searchField, string searchValue, string returnField)
        {
            return table.AsEnumerable().Where(x => x.Field<string>(searchField) == searchValue).Select(x => x.Field<string>(returnField)).FirstOrDefault();
        }

        //more overloads for several search fields and values go here
    }

Those classes are contained in a list (container) and I want to call GetValue on all MyClass classes which should return the first match. Something like that:

string result = myList.Select(x => x.GetValue("SearchField", "400", "ReturnField")).Where(x => x != null).FirstOrDefault();

Is it possible to dynamically create those methods on myList, so I can call

string result = myList.GetValue("SearchField", "400", "ReturnField");

?





Aucun commentaire:

Enregistrer un commentaire