interface

How to list interface methods omitting property accessors [duplicate]

眉间皱痕 提交于 2019-12-18 08:14:32
问题 This question already has an answer here : BindingFlags for Type.GetMethods excluding property accessors (1 answer) Closed 6 years ago . I would like to use reflection to display a list of methods in an interface. public interface IRoadVehicle { int WheelCount { get; } bool IsEmergency(); } I use following code: foreach (var m in typeof(IRoadVehicle).GetMethods()) { Console.WriteLine(m.Name); } However, I also get listed the compiler-generated property accessors if the interface has a

How to list interface methods omitting property accessors [duplicate]

喜夏-厌秋 提交于 2019-12-18 08:12:03
问题 This question already has an answer here : BindingFlags for Type.GetMethods excluding property accessors (1 answer) Closed 6 years ago . I would like to use reflection to display a list of methods in an interface. public interface IRoadVehicle { int WheelCount { get; } bool IsEmergency(); } I use following code: foreach (var m in typeof(IRoadVehicle).GetMethods()) { Console.WriteLine(m.Name); } However, I also get listed the compiler-generated property accessors if the interface has a

Why ArrayList implement IList, ICollection, IEnumerable?

試著忘記壹切 提交于 2019-12-18 07:41:26
问题 ArrayList declares that it implements the IList , ICollection , and IEnumeralbe interfaces. Why not only implement IList , because IList is also derived from ICollection , and ICollection is derived from IEnumerable . What's the purpose of this kind of declaration? There are many cases like this in .NET BCL. 回答1: With the following code: interface I1 { } interface I2 : I1 { } class Foo: I2 { } If you look at Foo through reflection you will find class Foo: I2, I1 { } Which is also valid to

Storing an object that implements multiple interfaces and derives from a certain base (.net)

安稳与你 提交于 2019-12-18 06:48:37
问题 In .net, it's possible to use generics so that a function can accept arguments which support one or more interfaces and derive from a base type, even if there does not exist any single type from which all valid argument types derive. For example, one could say: Sub Foo(Of T As {IInterface1, IInterface2, SomeBaseType})(Param as T) and be allowed to pass any derivative of SomeBaseType which implements both IInterface1 and IInterface2. This will work even if SomeBaseType does not support

What are the rules to handle homonym inherited methods?

纵饮孤独 提交于 2019-12-18 06:13:45
问题 I'm trying to understand how Java handles cases of ambiguity that come out when a concrete class inherits (abstract or concrete) methods having the same name from different classes/interfaces. I've not been able to find a general rule, this is why I decided, once for all, to spend some time on this by using a practical approach. I considered 8 different cases, combining abstract methods non-abstract methods abstract classes interfaces resulting in this scheme: +-------------------------+ |

The point of an Interface [duplicate]

二次信任 提交于 2019-12-18 05:59:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How will I know when to create an interface? I'm wondering about the point of using an Interface. Do you use Interfaces? If so, when do you decide to use them and when do you decide NOT to use them? I've currently got interfaces defined for my service layers and my repository layers, but I'm wondering if I'm missing out on other places where they'd be useful. I guess I just don't fully understand their purpose.

lambda expression on interface in Kotlin

可紊 提交于 2019-12-18 05:58:09
问题 I'm converting a project in Java to Kotlin and I'm surprise that interface made the code heavier in Kotlin than in Java. Example : I want to set the onBackPressListener in MainActivity from MyFragment. File 1: MainActivity, File 2: MyFragment, File 3: OnBackPressedListener (Interface) File 1 in Java, File 2 in Kotlin, File 3 in Java: activity.setOnBackPressed { /* Do something */ } File 1 in Kotlin, File 2 in Kotlin, File 3 in Java: activity.setOnBackPressed(OnBackPressedListener { /* Do

How to do proper Reflection of base Interface methods

徘徊边缘 提交于 2019-12-18 05:42:30
问题 I have 2 interfaces and 2 classes that I investigate via Reflection: IParent IChild - derives from IParent Parent Child - derives from Parent Strange thing for me is the fact that when I look through reflection on IChild type I don't find IParent method. Same code applied to Child type works as expected - reflection shows Parent method. interface IParent { void ParentMethod(); } interface IChild : IParent { void ChildMethod(); } class Parent { public void ParentMethod(){} } class Child :

Extend Date prototype with a interface Typescript

和自甴很熟 提交于 2019-12-18 05:07:08
问题 I want to add a getWeekNumber function to the Date prototype in javascript / typescript. I want to do it with an interface becease otherwise I get a error that he does not know the method getWeekNumber(). First I tried with a standart Date interface like this: interface Date { getWeekNumber(): number; } This had the resolve that all the methods of the Date are not call able anymore. I want to know of there is a way to extend the Date with an interface. 回答1: You can do it this way: in DateExt

Difference between generic argument constrained to an interface and just using the interface

百般思念 提交于 2019-12-18 04:38:19
问题 What is the difference between this: void MyMethod(IMyInterface value) { //... } and this: void MyMethod<T>(T value) where T : IMyInterface { //... } 回答1: The main functional difference is that you can know the actual type of the object inside of the generic method. The T parameter will contain the actual type which can advantageous in certain scenarios. In the non-generic case you cannot guarantee access to the underlying type of the object. Most of the type you could grab value.GetType()