public T Dummy <T>() { var fakeInterface = _fakeChainFactory.CreateFakeOrdinaryInterfaceGenerator <T>(); if (typeof(T).IsPrimitive) { return(_fakeChainFactory.GetUnconstrainedInstance <T>().Resolve(this)); } if (typeof(T) == typeof(string)) { return(_fakeChainFactory.GetUnconstrainedInstance <T>().Resolve(this)); } if (TypeOf <T> .IsImplementationOfOpenGeneric(typeof(IEnumerable <>))) { return(_emptyCollectionFixture.Create <T>()); } if (TypeOf <T> .IsOpenGeneric(typeof(IEnumerable <>))) { return((T)_emptyCollectionGenerator.EmptyEnumerableOf(typeof(T).GetCollectionItemType())); } if (typeof(T).IsAbstract) { return(default(T)); } if (fakeInterface.Applies()) { return(fakeInterface.Apply(this)); } return((T)FormatterServices.GetUninitializedObject(typeof(T))); }
public T Dummy <T>(GenerationTrace trace) { var fakeInterface = _fakeChainFactory.CreateFakeOrdinaryInterfaceGenerator <T>(); var unconstrainedChain = _fakeChainFactory.GetUnconstrainedInstance <T>(); if (typeof(T).IsPrimitive) { return(unconstrainedChain.Resolve(SynchronizedThis, trace)); } if (typeof(T) == typeof(string)) { return(unconstrainedChain.Resolve(SynchronizedThis, trace)); } var emptyCollectionInstantiation = new EmptyCollectionInstantiation(); if (TypeOf <T> .IsImplementationOfOpenGeneric(typeof(IEnumerable <>))) { return(emptyCollectionInstantiation.CreateCollectionPassedAsGenericType <T>()); } if (TypeOf <T> .IsOpenGeneric(typeof(IEnumerable <>))) { return((T)emptyCollectionInstantiation.EmptyEnumerableOf(typeof(T).GetCollectionItemType())); } if (typeof(T).IsAbstract) { return(default(T)); } if (fakeInterface.Applies()) { return(fakeInterface.Apply(SynchronizedThis, trace)); } return((T)FormatterServices.GetUninitializedObject(typeof(T))); }