How do you know which interfaces have implemented and inherited from that class (C #)

zhaozj2021-02-16  71

Possible situations: Inherit from one class, from one or more interfaces, inherit from one class and one or more interfaces. Use the Type class's BaseType property to get which class inherits the class. GetInterfaces method has achieved which interfaces have achieved. The test code is as follows: Class library code:

Using

?Tem;

Namespace

GetInterface

{?? public? Class? Class1?:? Class2, baseinterface, baseinterface1? {?? public? Class1 () ?? {?????} ?? public? void? AAA () ?? {??? console .Writeline ("it's? Aaa"); ??} ?? public? Void? Bbb () ?? {??? console.writeline ("it's? Bbb"); ??}?}? Public? Class? Class2 ? {?? public? Class2 ()? {??}?}? interface? baseinterface? {?? void? AAA ();?}? interface? baseinterface1? {?? void? bbb ();?}}

Display call display under WinForm:

TYPE? TYPE?

=

?

Typeof

(GetInterface.class1); type []? TypeInterface?

=

. Type.getInterfaces ();

Foreach

? (? Type? T?

in

? TypeInterface?)

{???? this.listbox1.items.add (t.toString ());

TYPE? TYPEBASECLASS?

=

? type.basetype;

THIS

.listbox1.items.add? (? typebaseclass.tostring ());

转载请注明原文地址:https://www.9cbs.com/read-14667.html

New Post(0)