Sunday 15 March 2015

c# - Getting list of Inherited types doesn't work for all types -


I've written a small method for the list of inherited types, but it's TreeNode For example, do not work with:

Consider this class:

  class B {} class A: B {} class C: triode {}  

and then:

  GetInheritedTypes (typef (a)); // Typef (B) GetInheritedTypes (typef (C)); // 0 items  

The method to list them:

  list & lt; Type & gt; GetInheritedTypes (type base type) {return assembly.gateAssamper (bastype) .GetTypes () Where type (type = & gt; type! = Base type & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp;;  

Why GetInheritedTypes (typeof (C)) instead of TypeOf (TreeNode) ?

Why GetInheritedTypes (typeof (C)) Returning 0 items instead of TypeOf (TreeNode)?

Because TreeNode in the same Constitution C as it is. Your query is "in all forms in the same assembly as C, give me those people who are capable of assigning".

I suspect that your real problem is:

How can I list all the types of any kind?

You do not do search for all kinds in an assembly and check to see which people are trying to find out That your mother is asking every person in your city "Are you the mother of Jack?" Instead of asking Jack, "Who is your mother?"

Something would be great:

  public static IEnumerable & lt; Type & gt; Base type (type of this type) {if (type == empty) Repeat new logic ("type"); Base type = type; Whereas (true) {baseType = baseType.BaseType; Break if (base type == blank); Yield yield basis type; }}  

asks a commenter

What if you want to get all the implemented interfaces?

call GetInterfaces () on type object

(A previous version of this post suggests the transitive closure of the interface; I had already forgotten GetInterfaces

Well, for example, suppose you have a type

  class D  <}  

and a square < / P>

  class e: d  {}  

Now you ask "given code In the assembly write all types of X list, that type of value should be assigned to a variable of type e X ". Well, D> is in the assembly; D & LT; T & A; Type is assigned to a variable of an e type D> int> , not a variable type D < There is a slight overlap in "Inheritance" with regard to "Assignable" relationship and relationship, but they are all same

Do not show that they are there.


No comments:

Post a Comment