c# - Get all inherited classes of a generic abstract class -


I am exploring a way to achieve all the sections that get the general abstract class, and each of them But do one method classes.

I went to class implementation to implement it, something like this:

  public abstract class abstract and end Lieutenant TresponseData & gt; Where TResponseData: IResponseData {public abstract zero search (); Public abstract GoodData Bindetata (TResponseData data); } Public interface Aiarssponsdeta {} public class Aarspons: Aiarspisensdeta {} public class Breshpens: Aiarssponsdeta {} public class A: Abstrekvest and LT; Essence & G; {Public override void search () / // AResponse // call override AResponse} public with Bainddeta () Guddata Bainddeta (Aarspons data) bind data GoodData from {// AResponse}} public class B: Abstrekvest & lt; BResponse & gt; {Public override void search () {// BResponse // call public override with BResponse} with Binddeta) GoodData BindData (BResponse data) Tie GoodData data from {// BResponse}}   

is working to find it, as long as I have all the A & A. Open the B class and Search () method for each code. With the non-common abstract element, I can use the following snippet to get classes

  var GETExecutingAssembly () GetTypes () where t.IsSubclassOf (typeof (AbstractRequest)) & amp; Amp; T.GetConstructor (Type.EmptyTypes)! = Tap Selection Activator.CreateInstance (T) as AbstractRequest;   

Again, how can I get all the sections A and B, which is the AbstractRequest & lt; AResponse & gt; and AbstractRequest & lt; BResponse & gt; Can be passed from ?

Edit: I forgot to mention that there will be many implementations similar to A or B, and will be added over time. If I want to solve an "elegant" (if possible), then I have to take care of implementation of C, D etc. Only.

Thank you!

In fact, by breaking the essence, finding an example of searching () (and only search) is getting an example : Public Essentials class AbstractRequest {Public abstract zero search (); } Public Abstract Class AbstractRequest & lt; TResponseData & gt; : Sarrest is where TResponseData: IResponseData {Public Bureau GoodData BindData (TResponseData data); }

And then you can use your original (non-normal) code:

  var example = T in the assembly. GetExecutingAssembly () GetTypes () where t.IsClass & amp; Amp; Typef (abaterequest) ISSacienfel (T) & amp; amp; T.GetConstructor (Type.EmptyTypes)! = Tap Selection Activator.CreateInstance (T) as AbstractRequest;  (old, busted solution)   

I think I would do something untested like this:

  var abstractRequestTypes = (assembly t. GETExecutingAssembly (). GetTypes (in) where t.IsClass & amp; amp; amp; type (Aiarssponsdeta) select KIsAssignableFrom (T) type (AbstractRequest & lt; & Gt;) MakeGenericType (T).) To create the list (); Var example type assembly assembly in T = by. GetTypes () where t.IsClass & amp; AbstractRequestTypes.Any (dt = & gt; dt.IsAssignableFrom (t));   

It should cover anything in the heritage hierarchy, by taking advantage of the type of barrier at AbstractRequest .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -