コード例 #1
0
ファイル: TypeSerializer.cs プロジェクト: floatyears/Decrypt
 public TypeSerializer(TypeModel model, Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType, MethodInfo factory)
 {
     Helpers.Sort(fieldNumbers, serializers);
     bool flag = false;
     for (int i = 1; i < fieldNumbers.Length; i++)
     {
         if (fieldNumbers[i] == fieldNumbers[i - 1])
         {
             throw new InvalidOperationException("Duplicate field-number detected; " + fieldNumbers[i].ToString() + " on: " + forType.FullName);
         }
         if (!flag && serializers[i].ExpectedType != forType)
         {
             flag = true;
         }
     }
     this.forType = forType;
     this.factory = factory;
     if (constructType == null)
     {
         constructType = forType;
     }
     else if (!forType.IsAssignableFrom(constructType))
     {
         throw new InvalidOperationException(forType.FullName + " cannot be assigned from " + constructType.FullName);
     }
     this.constructType = constructType;
     this.serializers = serializers;
     this.fieldNumbers = fieldNumbers;
     this.callbacks = callbacks;
     this.isRootType = isRootType;
     this.useConstructor = useConstructor;
     if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0)
     {
         baseCtorCallbacks = null;
     }
     this.baseCtorCallbacks = baseCtorCallbacks;
     if (Helpers.GetUnderlyingType(forType) != null)
     {
         throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
     }
     if (model.MapType(TypeSerializer.iextensible).IsAssignableFrom(forType))
     {
         if (forType.IsValueType || !isRootType || flag)
         {
             throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
         }
         this.isExtensible = true;
     }
     this.hasConstructor = (!constructType.IsAbstract && Helpers.GetConstructor(constructType, Helpers.EmptyTypes, true) != null);
     if (constructType != forType && useConstructor && !this.hasConstructor)
     {
         throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
     }
 }
コード例 #2
0
ファイル: MetaType.cs プロジェクト: yonglehou/Symbiote
        /// <summary>
        /// Assigns the callbacks to use during serialiation/deserialization.
        /// </summary>
        /// <param name="beforeSerialize">The name of the method (or null) called before serialization begins.</param>
        /// <param name="afterSerialize">The name of the method (or null) called when serialization is complete.</param>
        /// <param name="beforeDeserialize">The name of the method (or null) called before deserialization begins (or when a new instance is created during deserialization).</param>
        /// <param name="afterDeserialize">The name of the method (or null) called when deserialization is complete.</param>
        /// <returns>The set of callbacks.</returns>
        public MetaType SetCallbacks(string beforeSerialize, string afterSerialize, string beforeDeserialize, string afterDeserialize)
        {
            if (type.IsValueType)
            {
                throw new InvalidOperationException();
            }
            CallbackSet callbacks = Callbacks;

            callbacks.BeforeSerialize   = ResolveCallback(beforeSerialize);
            callbacks.AfterSerialize    = ResolveCallback(afterSerialize);
            callbacks.BeforeDeserialize = ResolveCallback(beforeDeserialize);
            callbacks.AfterDeserialize  = ResolveCallback(afterDeserialize);
            return(this);
        }
コード例 #3
0
ファイル: MetaType.cs プロジェクト: yonglehou/Symbiote
        /// <summary>
        /// Assigns the callbacks to use during serialiation/deserialization.
        /// </summary>
        /// <param name="beforeSerialize">The method (or null) called before serialization begins.</param>
        /// <param name="afterSerialize">The method (or null) called when serialization is complete.</param>
        /// <param name="beforeDeserialize">The method (or null) called before deserialization begins (or when a new instance is created during deserialization).</param>
        /// <param name="afterDeserialize">The method (or null) called when deserialization is complete.</param>
        /// <returns>The set of callbacks.</returns>
        public MetaType SetCallbacks(MethodInfo beforeSerialize, MethodInfo afterSerialize, MethodInfo beforeDeserialize, MethodInfo afterDeserialize)
        {
            if (type.IsValueType)
            {
                throw new InvalidOperationException();
            }
            CallbackSet callbacks = Callbacks;

            callbacks.BeforeSerialize   = beforeSerialize;
            callbacks.AfterSerialize    = afterSerialize;
            callbacks.BeforeDeserialize = beforeDeserialize;
            callbacks.AfterDeserialize  = afterDeserialize;
            return(this);
        }
コード例 #4
0
 // Token: 0x060002F5 RID: 757 RVA: 0x000101BC File Offset: 0x0000E3BC
 private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback)
 {
     this.metaType.ThrowIfFrozen();
     if (callback == null)
     {
         return(callback);
     }
     if (callback.IsStatic)
     {
         throw new ArgumentException("Callbacks cannot be static", "callback");
     }
     if (callback.ReturnType != model.MapType(typeof(void)) || !CallbackSet.CheckCallbackParameters(model, callback))
     {
         throw CallbackSet.CreateInvalidCallbackSignature(callback);
     }
     return(callback);
 }
コード例 #5
0
ファイル: MetaType.cs プロジェクト: yonglehou/Symbiote
 private static void CheckForCallback(MethodInfo method, object[] attributes, string callbackTypeName, ref MethodInfo[] callbacks, int index)
 {
     for (int i = 0; i < attributes.Length; i++)
     {
         if (attributes[i].GetType().FullName == callbackTypeName)
         {
             if (callbacks == null)
             {
                 callbacks = new MethodInfo[8];
             }
             else if (callbacks[index] != null)
             {
                 throw new InvalidOperationException("Duplicate " + callbackTypeName + " callbacks on " + method.ReflectedType.FullName);
             }
             callbacks[index] = method;
         }
     }
 }
コード例 #6
0
        public TypeSerializer(Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks)
        {
            Helpers.DebugAssert(forType != null);
            Helpers.DebugAssert(fieldNumbers != null);
            Helpers.DebugAssert(serializers != null);
            Helpers.DebugAssert(fieldNumbers.Length == serializers.Length);

            Helpers.Sort(fieldNumbers, serializers);
            bool hasSubTypes = false;
            for (int i = 1; i < fieldNumbers.Length; i++)
            {
                if (fieldNumbers[i] == fieldNumbers[i - 1]) throw new InvalidOperationException("Duplicate field-number detected; " +
                           fieldNumbers[i].ToString() + " on: " + forType.FullName);
                if(!hasSubTypes && serializers[i].ExpectedType != forType)
                {
                    hasSubTypes = true;
                }
            }
            this.forType = forType;
            this.serializers = serializers;
            this.fieldNumbers = fieldNumbers;
            this.callbacks = callbacks;
            this.isRootType = isRootType;
            this.useConstructor = useConstructor;
            
            if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0) baseCtorCallbacks = null;
            this.baseCtorCallbacks = baseCtorCallbacks;
#if !NO_GENERICS
            if (Nullable.GetUnderlyingType(forType) != null)
            {
                throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
            }
#endif
            
            if (typeof(IExtensible).IsAssignableFrom(forType))
            {
                if (forType.IsValueType || !isRootType || hasSubTypes)
                {
                    throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
                }
                isExtensible = true;
            }
        }
コード例 #7
0
 // Token: 0x0600038B RID: 907 RVA: 0x000135D0 File Offset: 0x000117D0
 internal void VerifyFactory(MethodInfo factory, Type type)
 {
     if (factory != null)
     {
         if (type != null && Helpers.IsValueType(type))
         {
             throw new InvalidOperationException();
         }
         if (!factory.IsStatic)
         {
             throw new ArgumentException("A factory-method must be static", "factory");
         }
         if (type != null && factory.ReturnType != type && factory.ReturnType != base.MapType(typeof(object)))
         {
             throw new ArgumentException("The factory-method must return object" + ((type == null) ? "" : (" or " + type.FullName)), "factory");
         }
         if (!CallbackSet.CheckCallbackParameters(this, factory))
         {
             throw new ArgumentException("Invalid factory signature in " + factory.DeclaringType.FullName + "." + factory.Name, "factory");
         }
     }
 }
コード例 #8
0
ファイル: TypeSerializer.cs プロジェクト: helios57/anrl
        public TypeSerializer(Type forType, int[] fieldNumbers, IProtoSerializer[] serializers, MethodInfo[] baseCtorCallbacks, bool isRootType, bool useConstructor, CallbackSet callbacks, Type constructType)
        {
            Helpers.DebugAssert(forType != null);
            Helpers.DebugAssert(fieldNumbers != null);
            Helpers.DebugAssert(serializers != null);
            Helpers.DebugAssert(fieldNumbers.Length == serializers.Length);

            Helpers.Sort(fieldNumbers, serializers);
            bool hasSubTypes = false;
            for (int i = 1; i < fieldNumbers.Length; i++)
            {
                if (fieldNumbers[i] == fieldNumbers[i - 1]) throw new InvalidOperationException("Duplicate field-number detected; " +
                           fieldNumbers[i].ToString() + " on: " + forType.FullName);
                if(!hasSubTypes && serializers[i].ExpectedType != forType)
                {
                    hasSubTypes = true;
                }
            }
            this.forType = forType;
            if (constructType == null)
            {
                constructType = forType;
            }
            else
            {
                if (!forType.IsAssignableFrom(constructType))
                {
                    throw new InvalidOperationException(forType.FullName + " cannot be assigned from "+ constructType.FullName);
                }
            }
            this.constructType = constructType;
            this.serializers = serializers;
            this.fieldNumbers = fieldNumbers;
            this.callbacks = callbacks;
            this.isRootType = isRootType;
            this.useConstructor = useConstructor;

            if (baseCtorCallbacks != null && baseCtorCallbacks.Length == 0) baseCtorCallbacks = null;
            this.baseCtorCallbacks = baseCtorCallbacks;
            #if !NO_GENERICS
            if (Nullable.GetUnderlyingType(forType) != null)
            {
                throw new ArgumentException("Cannot create a TypeSerializer for nullable types", "forType");
            }
            #endif

            if (typeof(IExtensible).IsAssignableFrom(forType))
            {
                if (forType.IsValueType || !isRootType || hasSubTypes)
                {
                    throw new NotSupportedException("IExtensible is not supported in structs or classes with inheritance");
                }
                isExtensible = true;
            }
            hasConstructor = !constructType.IsAbstract && constructType.GetConstructor(
                    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
                    null, Helpers.EmptyTypes, null) != null;

            if (constructType != forType && useConstructor && !hasConstructor)
            {
                throw new ArgumentException("The supplied default implementation cannot be created: " + constructType.FullName, "constructType");
            }
        }
コード例 #9
0
 private static void CheckForCallback(MethodInfo method, object[] attributes, string callbackTypeName, ref MethodInfo[] callbacks, int index)
 {
     for(int i = 0 ; i < attributes.Length ; i++)
     {
         if(attributes[i].GetType().FullName == callbackTypeName)
         {
             if (callbacks == null) { callbacks = new MethodInfo[8]; }
             else if (callbacks[index] != null)
             {
                 throw new InvalidOperationException("Duplicate " + callbackTypeName + " callbacks on " + method.ReflectedType.FullName);
             }
             callbacks[index] = method;
         }
     }
 }