interface

How to make a subclass implement an interface?

孤街醉人 提交于 2020-01-04 06:31:37
问题 I have already created a class and a subclass and have a bunch of code in both. I've created an interface in the parent class and I have no idea how to make my child class implement the interface :/ The code is: class Car { public interface ISmth { void MyMethod(); } } class MyCar : Car { //implement the interface } 回答1: This is how your code should probably be laid out. public interface ISmth { void MyMethod(); } class Car { } class MyCar : Car, ISmth { public void MyMethod() { } } There

How to make a subclass implement an interface?

▼魔方 西西 提交于 2020-01-04 06:31:14
问题 I have already created a class and a subclass and have a bunch of code in both. I've created an interface in the parent class and I have no idea how to make my child class implement the interface :/ The code is: class Car { public interface ISmth { void MyMethod(); } } class MyCar : Car { //implement the interface } 回答1: This is how your code should probably be laid out. public interface ISmth { void MyMethod(); } class Car { } class MyCar : Car, ISmth { public void MyMethod() { } } There

Non-generic interface as a synonym for generic one

江枫思渺然 提交于 2020-01-04 05:17:07
问题 I have one generic interface in c#, and almost always I use it with one of the types. I want to create a non-generic interface for that type and use it. Let's say, I've the following code: public interface IMyGenericList<out T> where T : IItem { IEnumerable<T> GetList(); } public class MyList<T> : IMyGenericList<T> where T : IItem { public IEnumerable<T> GetList() { return null; } } it works well. Most times I need IMyGenericList<IItem> , so i try the following: public interface IMyItemsList

How to get a pointer to a variable that's masked as an interface?

ぐ巨炮叔叔 提交于 2020-01-04 05:05:18
问题 I prefer not to dive into the rationale of the situation below. It has to do with unmarshaling an serialized object that can be any of a fixed set of types, but you don't know which type. I have the following types: type I interface { Do() } type someI struct {} func (i *someI) Do() {} type otherI struct {} func (i *otherI) Do() {} So, two structs of which the pointers implement interface I . Now I have this method that wants to return a value of type I : func GetSomeI(marshalled []byte) (I,

Installing the Android USB driver - not happening

送分小仙女□ 提交于 2020-01-04 04:20:17
问题 Using AVD, I successfully obtained the USB driver. I followed the instructions on this page USB Driver for Windows but Windows never prompted with the "Found new hardware..." message. I'm running Vista x64 SP2 and I can see the amd64 folder under ~\Android SDK\tools\usb_driver. The Manage Devices applet shows no listing for "ADB Interface" so it certainly appears that it is not there. I tried a scan for hardware changes -- nada. And running "adb devices" comes back empty (as expected). How do

Cannot pass variable of type conforming to generic constraint

蹲街弑〆低调 提交于 2020-01-04 02:53:09
问题 public interface ILovable<T> where T : IEquatable<T> { T Care(T t); } public class Me : ILovable<int> { public int Care(int i) { return i; } } Say I have the above. Now below function fails: private static void Colour<T>(ILovable<T> me) where T : IEquatable<T> { var z = me.Care(1); //cannot convert from 'int' to 'T' } What's failing the above piece of code? ILovable<T> has a Care function which intakes a T which is IEquatable<T> . In the above function I'm calling the same Care function and

How should I properly implement the core Clojure interfaces?

喜欢而已 提交于 2020-01-04 02:35:13
问题 If I'm implementing some data structure in Clojure using deftype , how should I decide which of the core Clojure interfaces to implement? I was unable to find a comprehensive guide to the various Clojure interfaces; in fact, the only relevant piece of information I was able to find was this question, which is very limited in scope. What I'm looking for is a list of each of the core Clojure interfaces, with a brief description of what it is and when you should implement it (or if you should

Does this interface already exist in the standard .NET libraries?

断了今生、忘了曾经 提交于 2020-01-04 02:04:12
问题 I found myself needing a simple generic interface, and I wrote it, but it turned out to be pretty much the world's simplest interface. I was wondering if it already exists by some other name. I just want to make sure I'm not reinventing something that is already included with the .NET framework. interface IReceiver<T> { void Receive(T obj); } I can't really find a good list of "standard" interfaces that came with .NET. Does the structure of this interface look familiar to anyone? Have I

Mongodb - how to deserialze when a property has an Interface return type

让人想犯罪 __ 提交于 2020-01-03 20:58:49
问题 I'm attempting to avoid introducing any dependencies between my Data layer and client code that makes use of this layer, but am running into some problems when attempting to do this with Mongo (using the MongoRepository) MongoRepository shows examples where you create Types that reflect your data structure, and inherit Entity where required. Eg. [CollectionName("track")] public class Track : Entity { public string name { get; set; } public string hash { get; set; } public Artist artist { get;

Covariance/Contravariance Conundrum when using generic interface constraints

不想你离开。 提交于 2020-01-03 19:35:25
问题 public interface IShape{} public class Rectangle : IShape{} public class Base{} public class Derived : Base{} public interface IFoo<out T, in U> where T : IShape where U : Base { T Convert(U myType); } public class MyFoo : IFoo<Rectangle, Derived> { public Rectangle Convert(Derived myType) { throw new NotImplementedException(); } } class Program { static void Main(string[] args) { IFoo<IShape, Base> hmm = new MyFoo(); } } Given the above code, the compiler is unable to determine how to assign