Пример #1
0
        public static object GetSafeUninitializedObject(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!(type is RuntimeType))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_InvalidType", new object[]
                {
                    type.ToString()
                }));
            }
            if (type == typeof(ConstructionCall) || type == typeof(LogicalCallContext) || type == typeof(SynchronizationAttribute))
            {
                return(FormatterServices.nativeGetUninitializedObject((RuntimeType)type));
            }
            object result;

            try
            {
                result = FormatterServices.nativeGetSafeUninitializedObject((RuntimeType)type);
            }
            catch (SecurityException innerException)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_Security", new object[]
                {
                    type.FullName
                }), innerException);
            }
            return(result);
        }
Пример #2
0
 public static object GetUninitializedObject(Type type)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (!(type is RuntimeType))
     {
         throw new SerializationException(Environment.GetResourceString("Serialization_InvalidType", new object[]
         {
             type.ToString()
         }));
     }
     return(FormatterServices.nativeGetUninitializedObject((RuntimeType)type));
 }