Esempio n. 1
0
    public object?Dummy(GenerationRequest request, Type type)
    {
        var smartType = SmartType.For(type);

        if (type.IsPrimitive)
        {
            return(_unconstrainedChain.Resolve(this, request, type));
        }

        if (type == typeof(string))
        {
            return(_unconstrainedChain.Resolve(this, request, type));
        }

        var emptyCollectionInstantiation = new EmptyCollectionInstantiation();

        if (smartType.IsImplementationOfOpenGeneric(typeof(IEnumerable <>)))
        {
            return(emptyCollectionInstantiation.CreateCollectionPassedAsGenericType(type));
        }

        if (smartType.IsOpenGeneric(typeof(IEnumerable <>)))
        {
            return(emptyCollectionInstantiation.EmptyEnumerableOf(type.GetCollectionItemType()));
        }

        if (type.IsAbstract)
        {
            return(default);
Esempio n. 2
0
        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)));
        }