interface

List of Interfaces vs. List of Derived Type - Cannot Convert Expression Type to Return Type

做~自己de王妃 提交于 2019-12-09 18:13:36
问题 Why does this work: public IList<ICoupon> GetCouponsForSite(string siteSlug) { var coupons = _db.Coupons.Where(x => x.Site.slug == siteSlug) .Select(x => new Coupon(x.id)); var list = new List<ICoupon>(); foreach (var coupon in coupons) { list.Add(coupon); } return list; } But this does does not work (error - cannot convert expression type to return type): public IList<ICoupon> GetCouponsForSite(string siteSlug) { return _db.Coupons.Where(x => x.Site.slug == siteSlug) .Select(x => new Coupon

List of generic interfaces

只愿长相守 提交于 2019-12-09 17:56:21
问题 If I have a generic interface with a couple of implementing classes such as: public interface IDataElement<T> { int DataElement { get; set; } T Value { get; set; } } public class IntegerDataElement : IDataElement<int> { public int DataElement { get; set; } public int Value { get; set; } } public class StringDataElement : IDataElement<String> { public int DataElement { get; set; } public String Value { get; set; } } Is it possible to pass a collection of the implementing classes of differing

Unit Testing Interfaces in Python

拈花ヽ惹草 提交于 2019-12-09 17:43:18
问题 I am currently learning python in preperation for a class over the summer and have gotten started by implementing different types of heaps and priority based data structures. I began to write a unit test suite for the project but ran into difficulties into creating a generic unit test that only tests the interface and is oblivious of the actual implementation. I am wondering if it is possible to do something like this.. suite = HeapTestSuite(BinaryHeap()) suite.run() suite = HeapTestSuite

use implementation type in interface in java

廉价感情. 提交于 2019-12-09 17:25:38
问题 I want to make an interface that forces each class that implements it to have a certain functionality, for the implemented class' type. So say I have classes MyClassA, MyClassB, MyClassC, etc. that all need a function on their own type: in MyClassA: public class MyClassA implements MyClass { MyClassA function(MyClassA x) { doSomethingImplementedInMyClassA(x); } } in MyClassB: public class MyClassB implements MyClass { MyClassB function(MyClassB x) { doSomethingImplementedInMyClassB(x); } }

Create XmlRpcUrl Interface at runtime

梦想与她 提交于 2019-12-09 16:25:58
问题 Currently I'm creating my XML-RPC using (xml-rpc.net) interfaces statically with the following statement: [XmlRpcUrl("http://dillieodigital.wordpress.com/xmlrpc.php")] public interface ICSBlog : IMetaWeblog { } However, I'd like to be able to specify the URL for the service at runtime, so I can dynamically switch to different services as needed. How would I go about doing this? 回答1: The URL can be set at runtime, for example: ISumAndDiff proxy = XmlRpcProxyGen.Create<ISumAndDiff>(); proxy.Url

JAXB - generated classes implement interface

僤鯓⒐⒋嵵緔 提交于 2019-12-09 15:41:53
问题 Is there a way to configure JAXB to so that a generated class implements a specified interface? I'm intending to use JAXB generated classes as DAO's and they should be able implement my DAO interface. 回答1: The interface injection plugin for XJC lets you do this. 回答2: Unfortunately, it looks like the interface-injection plugin mentioned in some of the other answers is no longer well supported. In fact, I'm having trouble finding the JAR for download. Thankfully, the JAXB2 Basics Plugins

Java - Interface extending itself

偶尔善良 提交于 2019-12-09 15:08:39
问题 I've been using this site for about 6 months now, and its time to ask my first question, because I cant find the answer to this, atleast not an answer that I can understand! In this bit of code, why is this interface extending itself? public interface PositionedVertex<V extends PositionedVertex<V>> { /** * @return Position for node data. */ public Point getPosition(); } Wouldnt this code do the same?: public interface PositionedVertex<V> { /** * @return Position for node data. */ public Point

forward declaration for objective-c interfaces

為{幸葍}努か 提交于 2019-12-09 14:34:51
问题 How do I forward declare this object: @interface MyClass : NSObject <AVAudioSessionDelegate> { } @end in objective c 回答1: This is a forward declaration of an ObjC type: @class MyClass; And this is a forward declaration of an ObjC protocol: @protocol AVAudioSessionDelegate; For those of you who are curious why this is useful: Forward declarations can be used to significantly reduce your dependencies and significantly reduce your build times because it allows you to avoid #import ing headers

Does Typescript support “subset types”?

耗尽温柔 提交于 2019-12-09 14:17:44
问题 Let's say I have an interface: interface IUser { email: string; id: number; phone: string; }; Then I have a function that expects a subset (or complete match) of that type. Maybe it will pass an entire object, made it will just pass in {email: "t@g.com"} . I want the type checker to allow for both. Example: function updateUser(user: IUser) { // Update a "subset" of user attributes: $http.put("/users/update", user); } Does Typescript support this sort of behavior yet? I could find it very

C# IEnumerable, ICollection, IList or List?

你。 提交于 2019-12-09 14:10:54
问题 Can somebody explain to me why we constantly use IEnumerable all over C# when, by my logic we should be using List , IList or ICollection instead. Look at this commit fix. Ok, number 1) IEnumarable should only be used for read only collections! Great, everybody keeps repeating that (I get it), so why do I need to constantly need putting ToList() on every single database call to prevent mulit-threads creashing when the original thread disposes of context. Surely once the query has been