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

DeclareLocal() private method

private DeclareLocal ( Type type, string name ) : LocalBuilder
type System.Type
name string
return System.Reflection.Emit.LocalBuilder
        internal LocalBuilder DeclareLocal(Type type, string name)
        {
            return DeclareLocal(type, name, false);
        }

Same methods

CodeGenerator::DeclareLocal ( Type type, string name, bool isPinned ) : LocalBuilder
CodeGenerator::DeclareLocal ( Type type, string name, object initialValue ) : LocalBuilder

Usage Example

コード例 #1
0
            private void CreateObject(ClassDataContract classContract)
            {
                Type type = _objectType = classContract.UnderlyingType;

                if (type.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.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::DeclareLocal