Suppose we are creating a generic control in .NET. E.g. a tree.
I don't understand why people use this generic type definition
Control<T>
when in Object Oriented Programming I can use an abstract class or an interface:
Control<IItem> or Control<BaseClass>
So the only thing to do is that, their types must derive from that base clas...
I want to achieve something like this in C# 3.5:
public void Register<T>() : where T : interface {}
I can do it with class or struct, but how to do it with an interface?
Thanks!
André
...
Hi all,
I have
interface FooI
class FooA implements FooI
class FooB implements FooI
class FooC implements FooI
I wrote a class "Handler" that has the following methods
static double handle(FooA f)
static double handle(FooB f)
static double handle(FooI f)
and I have a function like the following:
void caller(FooI f)
{
Handler....
Consider the following example. I have an interface MyInterface, and then two abstract classes MyAbstractClass1 and MyAbstractClass2. MyAbstractClass1 implements MyInterface, but MyAbstractClass2 does not.
Now I have three concrete classes.
MyConcreteClass1 is derived from MyAbstractClass1 but does not implement MyInterface.
MyConcr...
Updated question, see below
I'm starting a new project and I would like to experiment with components based architecture (I chose PyProtocols). It's a little program to display and interract with realtime graphics.
I started by designing the user input components:
IInputDevice - e.g. a mouse, keyboard, etc... An InputDevice may have ...
We have a content delivery system that delivers many different content types to devices.
All the content is stored in a database with a contentID & mediaTypeID.
For this example lets assume the MediaType can be one of these 2 but in reality theres many more of them.
Gif
MP3
Because the content is stored in different places based on m...
I have something that looks like the following:
[CoolnessFactor]
interface IThing {}
class Tester
{
static void TestSomeInterfaceStuff<T>()
{
var attributes = from attribute
in typeof(T).GetCustomAttributes(typeof(T), true)
where attributes == typeof(CoolnessFactorAttribu...
I'm trying to understand the Repository Pattern, while developing an ASP.NET MVC application (using .NET 3.5, ASP.NET MVC 1.0 and Entity Framework). I've gotten far enough to get the dependency injection and all working with one Controller and one Entity type, but now I've gotten as far as to implementing support for a relation between d...
As a sort of continuation of this, I have the following newbie question:
What difference is there in building a wrapper class that expects lots of inputs parameters and inputting those parameters directly into the final constructor?
Don't get me wrong, I think the multiple input parameter thing is pretty ugly, and I'm trying to get aro...
I'm doing some research in how to implement a event-handling scheme in C++ that can be easyest as its to implements an adpter to a class in java. The problem is that with the approach shown below, I will need to have all adapters already implemented with its function overriding in the devived class (because the linker needs it). On the o...
I've seen other threads saying java reflection performance is 10-100x slower than when using non-reflection calls.
My tests in 1.6 have shown that this is not the case but I found some other interesting things that I need someone to explain to me.
I have objects that implement my interface. I did three things 1) using a reference to a...
So, say I have a simple enum and a class that uses it:
enum ThingType { POTATO, BICYCLE };
class Thing {
public void setValueType(ThingType value) { ... }
public ThingType getValueType() { ... }
}
But, in reality, I have lots of different classes that implement setValueType, each with a different kind of enum. I want to make ...
I have an interface, and some classes that inherit from it.
public interface IFoo {}
public class Bar : IFoo {}
public class Baz : IFoo {}
If I get the types which implement IFoo, how can I decide if the type will represent a Bar or a Baz (without actually creating the object)?
// Get all types in assembly.
Type[] theTypes = asm.G...
Is there a way to require that a class have a particular abstract member? Something like this:
public interface IMaxLength
{
public static uint MaxLength { get; }
}
Or perhaps this:
public abstract class ComplexString
{
public abstract static uint MaxLength { get; }
}
I'd like a way enforce that a type (either through inher...
Hi,
I want to implement architecture involving different .NET assemblies (i.e. modules). Some of these modules should provide services which are used as .NET interfaces by other modules.
The modules should be loaded and registered dynamically at runtime, I do not want to have "hardcoded" dependencies between them.
Example:
Module1.d...
What do people think of the best guidelines to use in an interface? What should and shouldn't go into an interface?
I've heard people say that, as a general rule, an interface must only define behavior and not state. Does this mean that an interface shouldn't contain getters and setters?
My opinion: Maybe not so for setters, but some...
Hi,
I have a method:
public void StoreUsingKey<T>(T value) where T : class, new() {
var idModel = value as IIDModel;
if (idModel != null)
Store<T>(idModel);
AddToCacheUsingKey(value);
}
that I would like to optionally call the following method, based on the value parameter's implementation of IIDModel.
public void Store...
As a novice to OOP, I am trying to implement an interface method with a base parameter by passing a (needed) subclass parameter. I have:
public interface IArticleDataAccess { int SaveArticle(NewsArticle thisArticle); }
public AnalysisDataAccess : IArticleDataAccess {
public int SaveArticle(AnalysisArticle thisArticle) {
// Spec...
For example if I wanted to see what my .NET options were for something implementing IList or IDictionary. Is there a way to find that for example in the MSDN documentation?
...
This is the error I am getting in the handleModuleReady function:
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed:
can not convert MyModule@39b8479 to IModuleInterface.
I have an application setup and I have created modules to load at runtime in order to decrease the filesize (as most users will only ever ...