Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var obj= Activator.CreateInstance(GetType());
- public static Method<T>() where T : SomeBase, new()
- public interface ISomething
- {
- void DoSomething();
- }
- public class SomeClass : ISomething
- {
- public virtual void DoSomething() { Console.WriteLine("SomeClass"); }
- }
- public class SomeDerivedClass : SomeClass
- {
- private int parameter;
- public SomeDerivedClass(int parameter)
- {
- this.parameter = parameter;
- }
- public virtual void DoSomething()
- {
- Console.WriteLine("SomeDerivedClass - {0}", parameter);
- base.DoSomething();
- }
- }
- public interface IFactory
- {
- public ISomething Create();
- }
- public class SomeClassFactory : IFactory
- {
- public ISomething Create() { return new SomeClass(); }
- }
- public class SomeDerivedClassFactory : IFactory
- {
- public ISomething Create() { return new SomeDerivedClass(SomeParam); }
- public int SomeParam { get; set; }
- }
- MyClass myClass = new MyClassFactory().Create();
- public abstract class CreatorOf<T> where T : CreatorOf<T>
- {
- public static T Create()
- {
- return (T)Activator.CreateInstance(typeof(T));
- }
- }
- public class Inheritor : CreatorOf<Inheritor>
- {
- public Inheritor()
- {
- }
- }
- public class Client
- {
- public Client()
- {
- var obj = Inheritor.Create();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement