Esempio n. 1
0
        private object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (factory != null)
            {
                obj = InvokeCallback(factory, null, source.Context);
            }
            else if (useConstructor)
            {
                if (!hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(constructType);
                }
                obj = Activator.CreateInstance(constructType, nonPublic: true);
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }
        // Token: 0x0600029E RID: 670 RVA: 0x0000FC80 File Offset: 0x0000DE80
        private object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            object obj;

            if (this.factory != null)
            {
                obj = this.InvokeCallback(this.factory, null, source.Context);
            }
            else if (this.useConstructor)
            {
                if (!this.hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(this.constructType);
                }
                obj = Activator.CreateInstance(this.constructType, true);
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(this.constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (this.baseCtorCallbacks != null)
            {
                for (int i = 0; i < this.baseCtorCallbacks.Length; i++)
                {
                    this.InvokeCallback(this.baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && this.callbacks != null)
            {
                this.InvokeCallback(this.callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }
Esempio n. 3
0
        object CreateInstance(ProtoReader source)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (useConstructor)
            {
                if (!hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(constructType);
                }
                obj = Activator.CreateInstance(constructType
#if !CF && !SILVERLIGHT
                                               , true
#endif
                                               );
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }
Esempio n. 4
0
        public object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (_factory != null)
            {
                obj = InvokeCallback(_factory, null, _constructType, source.Context);
            }
            else if (_useConstructor && _hasConstructor)
            {
                obj = Activator.CreateInstance(_constructType
#if !CF && !SILVERLIGHT && !WINRT && !PORTABLE
                                               , true
#endif
                                               );
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(_constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (_baseCtorCallbacks != null)
            {
                for (int i = 0; i < _baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(_baseCtorCallbacks[i], obj, _constructType, source.Context);
                }
            }
            if (includeLocalCallback && _callbacks != null)
            {
                InvokeCallback(_callbacks.BeforeDeserialize, obj, _constructType, source.Context);
            }
            return(obj);
        }
Esempio n. 5
0
        public void TestDirectSkipConstructor()
        {
            var obj = new SkipCtorType();

            Assert.Equal(42, obj.Value);

            obj = (SkipCtorType)BclHelpers.GetUninitializedObject(typeof(SkipCtorType));
            Assert.Equal(0, obj.Value);
        }
Esempio n. 6
0
        object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj = null;

            if (model.netDataPoolDelegate != null)
            {
                // ========================================================
                // added by wsh @ 2017-07-01 for net data pool
                obj = model.netDataPoolDelegate(constructType);
                // ========================================================
            }
            if (obj == null)
            {
                if (factory != null)
                {
                    obj = InvokeCallback(factory, null, source.Context);
                }
                else if (useConstructor)
                {
                    if (!hasConstructor)
                    {
                        TypeModel.ThrowCannotCreateInstance(constructType);
                    }
                    obj = Activator.CreateInstance(constructType
#if !CF && !SILVERLIGHT && !WINRT && !PORTABLE
                                                   , true
#endif
                                                   );
                }
                else
                {
                    obj = BclHelpers.GetUninitializedObject(constructType);
                }
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }
        object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (factory != null)
            {
                obj = InvokeCallback(factory, null, source.Context);
            }
            else if (useConstructor)
            {
                if (!hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(constructType);
                }
#if PROFILE259
                ConstructorInfo constructorInfo = System.Linq.Enumerable.First(
                    constructType.GetTypeInfo().DeclaredConstructors, c => c.GetParameters().Length == 0);
                obj = constructorInfo.Invoke(new object[] {});
#else
                obj = Activator.CreateInstance(constructType
#if !(CF || SILVERLIGHT || WINRT || PORTABLE || NETSTANDARD1_3 || NETSTANDARD1_4)
                                               , nonPublic: true
#endif
                                               );
#endif
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }
        object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (factory != null)
            {
                obj = InvokeCallback(factory, null, source.Context);
            }
            else if (useConstructor)
            {
                if (!hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(constructType);
                }
                // ## 苦竹 修改 ##
                //        obj = Activator.CreateInstance(constructType
                //#if !(CF || SILVERLIGHT || WINRT || PORTABLE || NETSTANDARD1_3 || NETSTANDARD1_4)
                //                    , nonPublic: true
                //#endif
                //                    );
                obj = ActivatorUtils.FastCreateInstance(constructType);
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            return(obj);
        }