Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyGenericClass : DL
- //but i cannot do
- public class MyGenericClass <T> : T
- public class MyGenericClass <T>
- {
- T obj;
- //have all MyGenericClass.XYZ call obj.XYZ
- }
- public interface IXyzable { void xyz(); }
- public class MyGenericClass<T> : IXyzable where T : IXyzable {
- T obj;
- public void xyz() {
- obj.xyz();
- }
- }
- public interface Ixyz
- {
- void XYZ();
- }
- public class MyGenericClass<T> : Ixyz where T:Ixyz, new()
- {
- T obj;
- public MyGenericClass()
- {
- obj = new T();
- }
- public void XYZ()
- {
- obj.XYZ();
- }
- }
- var x = new MyGenericClass<MyGenericClass<SomeClass>>();
- public class MyGenericClass<T> : T
- public class MyGenericClass<T>
- {
- T obj;
- }
- public class MyGenericClass
- {
- object obj;
- }
- class MyBase
- {
- public virtual void MyVirtual() { }
- }
- class MyGenericDerived<T> : T
- {
- public override void MyVirtual()
- {
- Console.WriteLine("Overridden!");
- }
- }
- MyBase obj = new MyGenericDerived<MyBase>();
- obj.MyVirtual();
- class BaseClass<T>
- {
- public T property { get; set; }
- }
- class GenericClass<T> : BaseClass<T>
- {
- }
- class Program
- {
- static void Main(string[] args)
- {
- GenericClass<int> l = new GenericClass<int>();
- l.property = 10;
- }
- }
- class BaseGeneric<T>
- {
- private T obj;
- private MethodInfo mi;
- private const string MethodNameOfInterest = "Xyz";
- public BaseGeneric(T theObject)
- {
- this.obj = theObject;
- Type t = obj.GetType();
- mi = t.GetMethod(MethodNameOfInterest);
- }
- public void Xyz()
- {
- mi.Invoke(obj, null);
- }
- }
Add Comment
Please, Sign In to add comment