Ejemplo n.º 1
0
            public ViewEngineCollectionWithoutResolver()
            {
                var resolverField = typeof(ViewEngineCollection).GetField("_dependencyResolver",
                                                                          BindingFlags.NonPublic | BindingFlags.Instance);

                var resolver = new EmptyResolver();

                resolverField.SetValue(this, resolver);
            }
        /// <summary>
        /// Tries the create default resolver.
        /// </summary>
        /// <returns><c>true</c>, if create default resolver was tryed, <c>false</c> otherwise.</returns>
        /// <param name="type">Type.</param>
        /// <param name="resolver">Resolver.</param>
        private bool TryCreateDefaultResolver(Type type, out IResolver resolver)
        {
            if (type.IsValueType)                                                       //Проверяем является ли тип значимым
            {
                if (type.IsPrimitive && TryCreatePrimitiveResolver(type, out resolver)) //Проверяем является ли тип примитивным
                {
                    return(true);
                }

                if (TypeOf <Decimal> .Equals(type))
                {
                    resolver = new DecimalResolver();
                    return(true);
                }
            }
            else
            {
                if (type.IsArray)
                {
                    resolver = CreateArrayResolver(type);
                    return(true);
                }

                if (TypeOf <Object> .Equals(type))
                {
                    resolver = new ObjectResolver(); return(true);
                }
                if (TypeOf <String> .Equals(type))
                {
                    resolver = new StringResolver(); return(true);
                }
                if (RuntimeType.Equals(type))
                {
                    resolver = new TypeResolver(Serializator); return(true);
                }

                if (Delegate.IsAssignableFrom(type))
                {
                    if ((Serializator.Options & SerializatorOption.ThrowOutExceptions) != 0)
                    {
                        throw new NotSupportedException("Serialization delegates is not supported");
                    }
                    resolver = new EmptyResolver(Serializator);
                    return(true);
                }
            }

            resolver = null;
            return(false);
        }