3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
8 using System.Reflection;
9 using System.Security.Permissions;
10 using System.Runtime.InteropServices;
12 namespace System.Reflection.Emit
14 [ClassInterface(ClassInterfaceType.None)]
15 [ComDefaultInterface(typeof(_LocalBuilder))]
16 [System.Runtime.InteropServices.ComVisible(true)]
17 public sealed class LocalBuilder : LocalVariableInfo, _LocalBuilder
19 #region Private Data Members
20 private int m_localIndex;
21 private Type m_localType;
22 private MethodInfo m_methodBuilder;
23 private bool m_isPinned;
27 private LocalBuilder() { }
28 internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder)
29 : this(localIndex, localType, methodBuilder, false) { }
30 internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder, bool isPinned)
32 m_isPinned = isPinned;
33 m_localIndex = localIndex;
34 m_localType = localType;
35 m_methodBuilder = methodBuilder;
39 #region Internal Members
40 internal int GetLocalIndex()
44 internal MethodInfo GetMethodBuilder()
46 return m_methodBuilder;
50 #region LocalVariableInfo Override
51 public override bool IsPinned { get { return m_isPinned; } }
52 public override Type LocalType
59 public override int LocalIndex { get { return m_localIndex; } }
62 #region Public Members
63 public void SetLocalSymInfo(String name)
65 SetLocalSymInfo(name, 0, 0);
68 public void SetLocalSymInfo(String name, int startOffset, int endOffset)
71 SignatureHelper sigHelp;
77 MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
78 if (methodBuilder == null)
79 // it's a light code gen entity
80 throw new NotSupportedException();
81 dynMod = (ModuleBuilder) methodBuilder.Module;
82 if (methodBuilder.IsTypeCreated())
84 // cannot change method after its containing type has been created
85 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated"));
88 // set the name and range of offset for the local
89 if (dynMod.GetSymWriter() == null)
91 // cannot set local name if not debug module
92 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
95 sigHelp = SignatureHelper.GetFieldSigHelper(dynMod);
96 sigHelp.AddArgument(m_localType);
97 signature = sigHelp.InternalGetSignature(out sigLength);
99 // The symbol store doesn't want the calling convention on the
100 // front of the signature, but InternalGetSignature returns
101 // the callinging convention. So we strip it off. This is a
102 // bit unfortunate, since it means that we need to allocate
103 // yet another array of bytes...
104 mungedSig = new byte[sigLength - 1];
105 Array.Copy(signature, 1, mungedSig, 0, sigLength - 1);
107 index = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex();
110 // top level scope information is kept with methodBuilder
111 methodBuilder.m_localSymInfo.AddLocalSymInfo(
120 methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(
131 void _LocalBuilder.GetTypeInfoCount(out uint pcTInfo)
133 throw new NotImplementedException();
136 void _LocalBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
138 throw new NotImplementedException();
141 void _LocalBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
143 throw new NotImplementedException();
146 void _LocalBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
148 throw new NotImplementedException();