interface

Linq context object isn't registering as a type of System.IDisposable object

旧城冷巷雨未停 提交于 2019-12-09 14:10:54
问题 I'm trying to use my 'context' object in a using statement. It works on one project, but on another, I'm getting the following error. '...': type used in a using statement must be implicitly convertible to 'System.IDisposable' When I'm referring to the 'context' object, I'm referring to the object automatically created when you're working with LINQ to SQL. The class I'm working within, implements another interface, could that be screwing up this context object? using (TGDC context = new TGDC(

Visual Studio - automatically implement all inherited methods from an interface

↘锁芯ラ 提交于 2019-12-09 14:06:11
问题 Let's say we have a class called MyClass. public class MyClass We also have an interface like so: public interface MyInterface{ public string SomeFunction(int foo, string bar, short baz){} } We want this class to inherit from MyInterface. public class MyClass: MyInterface MyInterface has n properties, and i methods. How can I get Visual Studio to automatically implement all those methods and properties without the developer doing any of the legwork? 回答1: For C#, you can right click the

Java switch on enum that implements same interface

白昼怎懂夜的黑 提交于 2019-12-09 12:49:00
问题 I have a group project where we are forced to use interfaces and enumerations provided. Imagine a situation like below : // marker interface interface Request<T extends Response>{} // marker interface interface Response{} enum TypeAction implements Request<SomeEnumClassThatImplementsResponse>{ TYPE1, TYPE2, TYPE3 } enum OtherTypeAction implements Request<SomeOtherEnumClassThatImplementsResponse>{ OTHERTYPE1, OTHERTYPE2 } In an other class, I have a List of Request like this : List<Request>

Parallel Inheritance between Interface Classes and Implementation Classes in C++

为君一笑 提交于 2019-12-09 12:18:48
问题 I'm trying to use C++ abstract base class in the way similar with Java interface. Supposed that we have following interface classes with only pure virtual functions: class Shape { virtual double area()=0; }; class Square : public Shape { virtual void setLength(double length)=0; }; class Rectangle : public Square { virtual void setWidth(double width)=0; }; and I try to implement Square and Rectangle the following way: class SquareImpl : public Square { /*implementation*/ }; class RectangleImpl

Implementing a method of interface is overriding or not in java

╄→гoц情女王★ 提交于 2019-12-09 12:09:43
问题 I know this might be crazy but today one of my friend puzzled by asking when we implement an interface in java is it considered as method overriding. I told him it is not overriding as we are providing working(definition) of method first time when we implement any interface. To support multiple inheritance java provide interface but he was not convinced and was arguing. Please bring some light on to the topic. 回答1: The term "overriding" applies when there is an existing implementation of the

IEnumerable & IEnumerator

时光毁灭记忆、已成空白 提交于 2019-12-09 12:09:39
问题 Can anyone please explain to me what is the difference between IEnumerable & IEnumerator , and how to use them? Thanks!!! 回答1: Generally, an IEnumerable is an object which can be enumerated, such as a list or array. An IEnumerator is an object that stores the state of the enumeration. The reason they're not one and the same is that you could have multiple enumerations over the same object at the same time - even in a single-threaded application. For example, consider the following code:

Can you use the C# new keyword to expand properties on an interface?

戏子无情 提交于 2019-12-09 12:06:44
问题 I understand how the "new" keyword can hide methods in a derived class. However, what implications does it have for classes that implement interfaces that use the keyword? Consider this example, where I decide to expand an interface by making its properties read/write. public interface IReadOnly { string Id { get; } } public interface ICanReadAndWrite : IReadOnly { new string Id { get; set; } } Then you are able to do things like this: public IReadOnly SomeMethod() { // return an instance of

Observer Pattern in Swift

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 11:58:04
问题 I want to implement an observer pattern, but I do not find the proper programming language constructs in Swift (also 2.0). The main problems are: protocol and extension does not allow stored properties. In classes we could add stored properties, but we can not force a subclass to override some of its inherited methods. This is what I want: {class|protocol|extension|whathaveyou} Sensor { var observers = Array<Any>() // This is not possible in protocol and extensions // The following is does

Is the use of explicit interface implementation meant for hiding functionality?

浪子不回头ぞ 提交于 2019-12-09 11:23:54
问题 I use interfaces for decoupling my code. I am curious, is the usage of explicit interface implementation meant for hiding functionality? Example: public class MyClass : IInterface { void IInterface.NoneWillCall(int ragh) { } } What is the benefit and specific use case of making this available only explicitly via the interface? 回答1: There are two main uses for it in my experience: It allows you to overload methods by return value. For example, IEnumerable<T> and IEnumerable both declare

Interfaces inheritance in C#

牧云@^-^@ 提交于 2019-12-09 09:20:35
问题 I'm trying to overrun quite big (for me) problem that I came across while writing my application. Look at this, please (I will try to shorten the code for simplicity): I have root interface called IRepository<T> . Next, IBookRepository : IRepository<Book> Next, concrete class that implements it: BookRepository : IBookRepository In the RepositoryManager class I declared private IRepository<IRepoItem> currentRepo; IRepoItem is an interface that is implemented by Book class. Now, when I try to