System.Runtime.Serialization.CodeGenerator.InitObj C# (CSharp) Method

InitObj() private method

private InitObj ( Type valueType ) : void
valueType System.Type
return void
        internal void InitObj(Type valueType)
        {
            if (_codeGenTrace != CodeGenTrace.None)
                EmitSourceInstruction("Initobj " + valueType);
            _ilGen.Emit(OpCodes.Initobj, valueType);
        }

Usage Example

コード例 #1
0
            private void CreateObject(ClassDataContract classContract)
            {
                Type type = _objectType = classContract.UnderlyingType;
                if (type.GetTypeInfo().IsValueType && !classContract.IsNonAttributedType)
                    type = Globals.TypeOfValueType;

                _objectLocal = _ilg.DeclareLocal(type, "objectDeserialized");

                if (classContract.UnderlyingType == Globals.TypeOfDBNull)
                {
                    _ilg.LoadMember(Globals.TypeOfDBNull.GetField("Value"));
                    _ilg.Stloc(_objectLocal);
                }
                else if (classContract.IsNonAttributedType)
                {
                    if (type.GetTypeInfo().IsValueType)
                    {
                        _ilg.Ldloca(_objectLocal);
                        _ilg.InitObj(type);
                    }
                    else
                    {
                        _ilg.New(classContract.GetNonAttributedTypeConstructor());
                        _ilg.Stloc(_objectLocal);
                    }
                }
                else
                {
                    _ilg.Call(null, XmlFormatGeneratorStatics.GetUninitializedObjectMethod, DataContract.GetIdForInitialization(classContract));
                    _ilg.ConvertValue(Globals.TypeOfObject, type);
                    _ilg.Stloc(_objectLocal);
                }
            }
All Usage Examples Of System.Runtime.Serialization.CodeGenerator::InitObj