interface

Optional Readonly Property in VB.Net Interface

I am trying to develop a simple interface for allowing quick lists to be generated from classes. Basically, the interface needs to return an ID and a Name. However, some classes have a calculated name property which is read only, others just use a read/write name property. Basically, all I care is that it has a getter, it does not matter...

Is there a way to make derived classes override ToString()?

(I'm working in .NET 4.0 beta, C#.) I have an interface, and all classes derived from this interface should implement custom ToString() logic. Is that enforceable? If so, how? ...

How can you return a Collection<T> as a Collection<Interface>?

I have a concrete class that contains a collection of another concrete class. I would like to expose both classes via interfaces, but I am having trouble figuring out how I can expose the Collection<ConcreteType> member as a Collection<Interface> member. I am currently using .NET 2.0 The code below results in a compiler error: Canno...

Does custom events in an interface override default Form events?

I have taken over a project, that have been coded by someone else. There are weird stuff in it like this: An interface declaring a custom event named Load ( event EventHandler Load; ) Since the Form class has its own Load event, what is supposed to happen when this interface is implemented? Is it some form of overriding the default event...

Good Case For Interfaces

I work at a company where some require justification for the use of an Interface in our code (Visual Studio C# 3.5). I would like to ask for an Iron Clad reasoning that interfaces are required for. (My goal is to PROVE that interfaces are a normal part of programming.) I don't need convincing, I just need a good argument to use in the...

new word in interfaces in c#

using System; namespace random { interface IHelper { void HelpMeNow(); } public class Base : IHelper { public void HelpMeNow() { Console.WriteLine("Base.HelpMeNow()"); } } public class Derived : Base { public new void HelpMeNow() ///this lin...

Class vs Interface

Recently I was asked in an interview that, can an Interface be considered as a class in C#? I.e. is an interface is a class in C#? I was confused. What can be the answer? ...

c# Properties in Abstract Base Classes

I have a strange problem that I could not solve. When I try to compile the following snipped I get this error: 'AbstractClass' does not implement interface member 'Property' (Compiler Error CS0535) The online help tells me to make my AbstractClass abstract, which it is. Can anybody tell me where I went wrong? Cheers Rüdiger public in...

Anthropomorphising interfaces - good or bad idea?

I have for some time tried to anthropomorphise (meaning human readable) the names I give to interfaces, to me this is the same as give an interface a role based name – trying to capture the purpose of the interface in the name. I was having a discussion with other developers who think this is a little strange and childish. What do the ...

How can I cast an Interface as it's type in c#?

Hello Everyone, I have a property that returns an interface. During debugging I can break on what was returned and while it is the interface, Visual Studio is smart enough to know the derived type that it actually is. I assume it's using reflection or something. I'm not sure. My question is, can I have that same info avaialble to me at r...

Implement an Interface with Generic Methods

I'm drawing a blank on this one and can't seem to find any previous example that I wrote. I'm trying to implement a generic interface with a class. When I implement the interface I think something isn't working right because Visual Studio continually produces errors saying that I'm not implmenting all of the methods in the Generic Interf...

Implementing Nullable Types in Generic Interface

So in a previous question I asked about implementing a generic interface with a public class and bingo, it works. However, one of the types I'm looking to pass in is one of the built in nullable types such as: int, Guid, String, etc. Here's my Interface: public interface IOurTemplate<T, U> where T : class where U : class { ...

Are there any fluent WPF projects?

As part of my on-going attempt to come to terms with WPF/XAML, I've become interested in the application of fluent interfaces to UI coding. I am aware of Fluent Silverlight (http://code.google.com/p/fluent-silverlight/), but I can't seem to find anything equivalent for WPF. Just as a personal note, I'm finding it very difficult to buy ...

setter for a property not defined in the interface

If my interface has the signature only for getter such as: public interface IInterface { object Id{get;} } So the interface only dictates a public getter for Id on any implemented class now when i have the class : public class Simple : IInterface { object Id { get{return something;} set{ do something else;} } } t...

Tag Interface for Singletons

The 'singleton-ness' of a class is an important aspect of how a class should be used. However, it usually doesn't have any explicit status in the exposed API of a class. Yes, conventional method names such as getInstance() are often used, but that's not exactly what I'm referring to here. A 'tag interface' is an interface which contains...

Using interfaces with Linq-to-Sql for decoupling

I am re-factoring a model class into an interface. The model class is auto-generated with Linq-to-Sql. class FooRepository { // ... public void Add(IFoo foo) { db.Foos.InsertOnSubmit(foo); } } The InsertOnSubmit method takes an instance of Foo, not an IFoo. I can cast the instance inline to (Foo) and th...

Generic classes with methods that work only for some type parameters

Say that you're writing a library to display things on the screen, so you create an IDisplayable interface. This interface has one method to create a control from the object: displayable.GetControl(). You want to create your own list type that can be displayed: MyList<T>. Now this list can only be displayed if T is an IDisplayable, so y...

Typing for a clone method specified in an interface

I'm writing an interface that requires classes to implement a clone() method. My naive approach to this went along the following lines: public interface ISolvableGame { function clone():ISolvableGame; //... } elsewhere: public class MyGame implements ISolvableGame { public function clone():MyGame { // ... } } ...

Java interface "Alias"

Consider the following two Java files that contain a simplified version of my issue #a.java package a; public interface I { //... } #b.java package b; public interface I { //... (different stuff from a.I) } You'll notice within my project there are two interfaces named "I". This cannot be changed. I am in a situation where I need t...

IMAP interface access to existing user messaging system in Python

I am running a site where users can private message each other. As with any other such website, to read and mark their messages, users must log on to the site. I wish to expose an IMAP interface so that users may read their site messages using their standard email client. There would be few complications in such approach as what be user...