Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Something : ITest<String>
- {
- private Something() { }
- }
- public interface ITest<T>
- where T : ITest<T>, new()
- {
- }
- public class A : ITest<A>
- {
- }
- public class B : ITest<A>
- {
- private B() { }
- }
- interface ITest<T> where T: new()
- {
- //...
- }
- class Test: ITest<Test>
- {
- //...
- }
- public interface IInterface
- {
- void DoSomething();
- }
- public class Foo : IInterface
- {
- public void DoSomething() { /* whatever */ }
- }
- public IInterface CreateUsingType(Type thingThatCreates)
- {
- ConstructorInfo constructor = thingThatCreates.GetConstructor(Type.EmptyTypes);
- return (IInterface)constructor.Invoke(new object[0]);
- }
- public void Test()
- {
- IInterface thing = CreateUsingType(typeof(Foo));
- }
- public interface IFactory
- {
- IInterface Create();
- }
- public class Factory<T> where T : IInterface, new()
- {
- public IInterface Create() { return new T(); }
- }
- public IInterface CreateUsingFactory(IFactory factory)
- {
- return factory.Create();
- }
- public void Test()
- {
- IInterface thing = CreateUsingFactory(new Factory<Foo>());
- }
- public IInterface CreateUsingDelegate(Func<IInterface> createCallback)
- {
- return createCallback();
- }
- public void Test()
- {
- IInterface thing = CreateUsingDelegate(() => new Foo());
- }
- void RegisterType<T>() where T:ITest, new() {
- }
- interface FooFactory {
- Foo createInstance();
- }
Add Comment
Please, Sign In to add comment