The Labs \ Source Viewer \ SSCLI \ System.Reflection.Emit \ LocalBuilder

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. using System;
  16. using System.Reflection;
  17. using System.Security.Permissions;
  18. using System.Runtime.InteropServices;
  19. namespace System.Reflection.Emit
  20. {
  21.     [ClassInterface(ClassInterfaceType.None)]
  22.     [ComDefaultInterface(typeof(_LocalBuilder))]
  23.     [System.Runtime.InteropServices.ComVisible(true)]
  24.     public sealed class LocalBuilder : LocalVariableInfo, _LocalBuilder
  25.     {
  26.         #region Private Data Members
  27.         private int m_localIndex;
  28.         private Type m_localType;
  29.         private MethodInfo m_methodBuilder;
  30.         private bool m_isPinned;
  31.         #endregion
  32.        
  33.         #region Constructor
  34.         private LocalBuilder()
  35.         {
  36.         }
  37.         internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder) : this(localIndex, localType, methodBuilder, false)
  38.         {
  39.         }
  40.         internal LocalBuilder(int localIndex, Type localType, MethodInfo methodBuilder, bool isPinned)
  41.         {
  42.             m_isPinned = isPinned;
  43.             m_localIndex = localIndex;
  44.             m_localType = localType;
  45.             m_methodBuilder = methodBuilder;
  46.         }
  47.         #endregion
  48.        
  49.         #region Internal Members
  50.         internal int GetLocalIndex()
  51.         {
  52.             return m_localIndex;
  53.         }
  54.         internal MethodInfo GetMethodBuilder()
  55.         {
  56.             return m_methodBuilder;
  57.         }
  58.         #endregion
  59.        
  60.         #region LocalVariableInfo Override
  61.         public override bool IsPinned {
  62.             get { return m_isPinned; }
  63.         }
  64.         public override Type LocalType {
  65.             get { return m_localType; }
  66.         }
  67.         public override int LocalIndex {
  68.             get { return m_localIndex; }
  69.         }
  70.         #endregion
  71.        
  72.         #region Public Members
  73.         public void SetLocalSymInfo(string name)
  74.         {
  75.             SetLocalSymInfo(name, 0, 0);
  76.         }
  77.         public void SetLocalSymInfo(string name, int startOffset, int endOffset)
  78.         {
  79.             ModuleBuilder dynMod;
  80.             SignatureHelper sigHelp;
  81.             int sigLength;
  82.             byte[] signature;
  83.             byte[] mungedSig;
  84.             int index;
  85.            
  86.             MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
  87.             if (methodBuilder == null)
  88.                 // it's a light code gen entity
  89.                 throw new NotSupportedException();
  90.             dynMod = (ModuleBuilder)methodBuilder.Module;
  91.             if (methodBuilder.IsTypeCreated()) {
  92.                 // cannot change method after its containing type has been created
  93.                 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated"));
  94.             }
  95.            
  96.             // set the name and range of offset for the local
  97.             if (dynMod.GetSymWriter() == null) {
  98.                 // cannot set local name if not debug module
  99.                 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
  100.             }
  101.            
  102.             sigHelp = SignatureHelper.GetFieldSigHelper(dynMod);
  103.             sigHelp.AddArgument(m_localType);
  104.             signature = sigHelp.InternalGetSignature(out sigLength);
  105.            
  106.             // The symbol store doesn't want the calling convention on the
  107.             // front of the signature, but InternalGetSignature returns
  108.             // the callinging convention. So we strip it off. This is a
  109.             // bit unfortunate, since it means that we need to allocate
  110.             // yet another array of bytes...
  111.             mungedSig = new byte[sigLength - 1];
  112.             Array.Copy(signature, 1, mungedSig, 0, sigLength - 1);
  113.            
  114.             index = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex();
  115.             if (index == -1) {
  116.                 // top level scope information is kept with methodBuilder
  117.                 methodBuilder.m_localSymInfo.AddLocalSymInfo(name, mungedSig, m_localIndex, startOffset, endOffset);
  118.             }
  119.             else {
  120.                 methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(name, mungedSig, m_localIndex, startOffset, endOffset);
  121.             }
  122.         }
  123.         #endregion
  124.        
  125.         void _LocalBuilder.GetTypeInfoCount(out uint pcTInfo)
  126.         {
  127.             throw new NotImplementedException();
  128.         }
  129.        
  130.         void _LocalBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
  131.         {
  132.             throw new NotImplementedException();
  133.         }
  134.        
  135.         void _LocalBuilder.GetIDsOfNames(        [In()]
  136. ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  137.         {
  138.             throw new NotImplementedException();
  139.         }
  140.        
  141.         void _LocalBuilder.Invoke(uint dispIdMember,         [In()]
  142. ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  143.         {
  144.             throw new NotImplementedException();
  145.         }
  146.     }
  147. }

Developer Fusion