mscorlib(4.0.0.0) API with additions
LocalBuilder.cs
2 
4 {
6  [ClassInterface(ClassInterfaceType.None)]
7  [ComDefaultInterface(typeof(_LocalBuilder))]
8  [ComVisible(true)]
10  {
11  private int m_localIndex;
12 
13  private Type m_localType;
14 
15  private MethodInfo m_methodBuilder;
16 
17  private bool m_isPinned;
18 
22  public override bool IsPinned => m_isPinned;
23 
26  public override Type LocalType => m_localType;
27 
30  public override int LocalIndex => m_localIndex;
31 
32  private LocalBuilder()
33  {
34  }
35 
36  internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder)
37  : this(localIndex, localType, methodBuilder, isPinned: false)
38  {
39  }
40 
41  internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder, bool isPinned)
42  {
43  m_isPinned = isPinned;
44  m_localIndex = localIndex;
45  m_localType = localType;
46  m_methodBuilder = methodBuilder;
47  }
48 
49  internal int GetLocalIndex()
50  {
51  return m_localIndex;
52  }
53 
54  internal MethodInfo GetMethodBuilder()
55  {
56  return m_methodBuilder;
57  }
58 
63  public void SetLocalSymInfo(string name)
64  {
65  SetLocalSymInfo(name, 0, 0);
66  }
67 
74  public void SetLocalSymInfo(string name, int startOffset, int endOffset)
75  {
76  MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
77  if (methodBuilder == null)
78  {
79  throw new NotSupportedException();
80  }
81  ModuleBuilder moduleBuilder = (ModuleBuilder)methodBuilder.Module;
82  if (methodBuilder.IsTypeCreated())
83  {
84  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated"));
85  }
86  if (moduleBuilder.GetSymWriter() == null)
87  {
88  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
89  }
90  SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper(moduleBuilder);
91  fieldSigHelper.AddArgument(m_localType);
92  int length;
93  byte[] sourceArray = fieldSigHelper.InternalGetSignature(out length);
94  byte[] array = new byte[length - 1];
95  Array.Copy(sourceArray, 1, array, 0, length - 1);
96  int currentActiveScopeIndex = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex();
97  if (currentActiveScopeIndex == -1)
98  {
99  methodBuilder.m_localSymInfo.AddLocalSymInfo(name, array, m_localIndex, startOffset, endOffset);
100  }
101  else
102  {
103  methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(name, array, m_localIndex, startOffset, endOffset);
104  }
105  }
106 
110  void _LocalBuilder.GetTypeInfoCount(out uint pcTInfo)
111  {
112  throw new NotImplementedException();
113  }
114 
120  void _LocalBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
121  {
122  throw new NotImplementedException();
123  }
124 
132  void _LocalBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
133  {
134  throw new NotImplementedException();
135  }
136 
147  void _LocalBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
148  {
149  throw new NotImplementedException();
150  }
151  }
152 }
override bool IsPinned
Gets a value indicating whether the object referred to by the local variable is pinned in memory.
Definition: LocalBuilder.cs:22
void AddArgument(Type clsArgument)
Adds an argument to the signature.
static SignatureHelper GetFieldSigHelper(Module mod)
Returns a signature helper for a field.
override int LocalIndex
Gets the zero-based index of the local variable within the method body.
Definition: LocalBuilder.cs:30
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
Definition: __Canon.cs:3
void SetLocalSymInfo(string name)
Sets the name of this local variable.
Definition: LocalBuilder.cs:63
Provides methods for building signatures.
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
override Module Module
Gets the module in which the current method is being defined.
Exposes the T:System.Reflection.Emit.LocalBuilder class to unmanaged code.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
Defines and represents a module in a dynamic assembly.
ILGenerator GetILGenerator()
Returns an ILGenerator for this method with a default Microsoft intermediate language (MSIL) stream s...
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Represents a local variable within a method or constructor.
Definition: LocalBuilder.cs:9
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
Defines and represents a method (or constructor) on a dynamic class.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
ISymbolWriter GetSymWriter()
Returns the symbol writer associated with this dynamic module.
Discovers the attributes of a local variable and provides access to local variable metadata.
void SetLocalSymInfo(string name, int startOffset, int endOffset)
Sets the name and lexical scope of this local variable.
Definition: LocalBuilder.cs:74
The exception that is thrown when a method call is invalid for the object's current state.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
The exception that is thrown when a requested method or operation is not implemented.
override Type LocalType
Gets the type of the local variable.
Definition: LocalBuilder.cs:26
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).