tags:

views:

54

answers:

2

I have a class called TASKS.

I want one property of the class to be dynamic enough to handle a structure change in the strong type. for example....

Class MyClass
 {
    public [mychangingProperty] - can be any strongly typed class....
 }

How is this possible?

+8  A: 

It can't be both strongly typed and dynamic; there are largely opposites.

One option here might be generics:

class MyClass<T> {
    public T Value {get;set;}
}

i.e. have a MyClass<Foo> and a MyClass<Bar> (with Foo Value and Bar Value respectively).

Other options:

  • use an interface/base-class that describes the common functionality between the values
  • use object and do the casting/reflection etc yourself
  • use C# 4.0 and dynamic (not yet released...)
Marc Gravell
A: 

probably, if I correct understand, you want to use Generics

kentaromiura