Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / Reflection / Emit / MethodRental.cs / 1 / MethodRental.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: MethodRental ** ** ** MethodRental class is to provide a fast way to swap method body implementation ** given a method of a class ** ** ===========================================================*/ namespace System.Reflection.Emit { using System; using System.Reflection; using System.Threading; using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Globalization; // MethodRental class provides the ability to insert a new method body of an // existing method on a class defined in a DynamicModule. // Can throw OutOfMemory exception. // //This class contains only static methods and does not require serialization. [HostProtection(MayLeakOnAbort = true)] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(_MethodRental))] [System.Runtime.InteropServices.ComVisible(true)] sealed public class MethodRental : _MethodRental { public const int JitOnDemand = 0x0000; // jit the method body when it is necessary public const int JitImmediate = 0x0001; // jit the method body now [SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode=true)] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void SwapMethodBody( Type cls, // [in] class containing the method int methodtoken, // [in] method token IntPtr rgIL, // [in] pointer to bytes int methodSize, // [in] the size of the new method body in bytes int flags) // [in] flags { if (methodSize <= 0 || methodSize >= 0x3f0000) throw new ArgumentException(Environment.GetResourceString("Argument_BadSizeForData"), "methodSize"); if (cls==null) throw new ArgumentNullException("cls"); // can only swap method body on dynamic module if (!(cls.Module is ModuleBuilder)) throw new NotSupportedException(Environment.GetResourceString("NotSupported_NotDynamicModule")); RuntimeType rType; if (cls is TypeBuilder) { // If it is a TypeBuilder, make sure that TypeBuilder is already been baked. TypeBuilder typeBuilder = (TypeBuilder) cls; if (typeBuilder.m_hasBeenCreated == false) throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("NotSupported_NotAllTypesAreBaked"), typeBuilder.Name)); // get the corresponding runtime type for the TypeBuilder. rType = typeBuilder.m_runtimeType as RuntimeType; } else { rType = cls as RuntimeType; } if (rType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "cls"); StackCrawlMark mark = StackCrawlMark.LookForMyCaller; if (rType.Assembly.m_assemblyData.m_isSynchronized) { lock(rType.Assembly.m_assemblyData) { SwapMethodBodyHelper(rType, methodtoken, rgIL, methodSize, flags, ref mark); } } else { SwapMethodBodyHelper(rType, methodtoken, rgIL, methodSize, flags, ref mark); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] internal extern static void SwapMethodBodyHelper( RuntimeType cls, // [in] class containing the method int methodtoken, // [in] method token IntPtr rgIL, // [in] pointer to bytes int methodSize, // [in] the size of the new method body in bytes int flags, // [in] flags ref StackCrawlMark stackMark); // [in] stack crawl mark used to find caller // private constructor to prevent class to be constructed. private MethodRental() {} void _MethodRental.GetTypeInfoCount(out uint pcTInfo) { throw new NotImplementedException(); } void _MethodRental.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) { throw new NotImplementedException(); } void _MethodRental.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) { throw new NotImplementedException(); } void _MethodRental.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) { throw new NotImplementedException(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: MethodRental ** ** ** MethodRental class is to provide a fast way to swap method body implementation ** given a method of a class ** ** ===========================================================*/ namespace System.Reflection.Emit { using System; using System.Reflection; using System.Threading; using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Globalization; // MethodRental class provides the ability to insert a new method body of an // existing method on a class defined in a DynamicModule. // Can throw OutOfMemory exception. // //This class contains only static methods and does not require serialization. [HostProtection(MayLeakOnAbort = true)] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(_MethodRental))] [System.Runtime.InteropServices.ComVisible(true)] sealed public class MethodRental : _MethodRental { public const int JitOnDemand = 0x0000; // jit the method body when it is necessary public const int JitImmediate = 0x0001; // jit the method body now [SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode=true)] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void SwapMethodBody( Type cls, // [in] class containing the method int methodtoken, // [in] method token IntPtr rgIL, // [in] pointer to bytes int methodSize, // [in] the size of the new method body in bytes int flags) // [in] flags { if (methodSize <= 0 || methodSize >= 0x3f0000) throw new ArgumentException(Environment.GetResourceString("Argument_BadSizeForData"), "methodSize"); if (cls==null) throw new ArgumentNullException("cls"); // can only swap method body on dynamic module if (!(cls.Module is ModuleBuilder)) throw new NotSupportedException(Environment.GetResourceString("NotSupported_NotDynamicModule")); RuntimeType rType; if (cls is TypeBuilder) { // If it is a TypeBuilder, make sure that TypeBuilder is already been baked. TypeBuilder typeBuilder = (TypeBuilder) cls; if (typeBuilder.m_hasBeenCreated == false) throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("NotSupported_NotAllTypesAreBaked"), typeBuilder.Name)); // get the corresponding runtime type for the TypeBuilder. rType = typeBuilder.m_runtimeType as RuntimeType; } else { rType = cls as RuntimeType; } if (rType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "cls"); StackCrawlMark mark = StackCrawlMark.LookForMyCaller; if (rType.Assembly.m_assemblyData.m_isSynchronized) { lock(rType.Assembly.m_assemblyData) { SwapMethodBodyHelper(rType, methodtoken, rgIL, methodSize, flags, ref mark); } } else { SwapMethodBodyHelper(rType, methodtoken, rgIL, methodSize, flags, ref mark); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] internal extern static void SwapMethodBodyHelper( RuntimeType cls, // [in] class containing the method int methodtoken, // [in] method token IntPtr rgIL, // [in] pointer to bytes int methodSize, // [in] the size of the new method body in bytes int flags, // [in] flags ref StackCrawlMark stackMark); // [in] stack crawl mark used to find caller // private constructor to prevent class to be constructed. private MethodRental() {} void _MethodRental.GetTypeInfoCount(out uint pcTInfo) { throw new NotImplementedException(); } void _MethodRental.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) { throw new NotImplementedException(); } void _MethodRental.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) { throw new NotImplementedException(); } void _MethodRental.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) { throw new NotImplementedException(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextAnchor.cs
- RemotingConfigParser.cs
- DbConvert.cs
- returneventsaver.cs
- RoutedCommand.cs
- DecimalAnimationUsingKeyFrames.cs
- ProcessHost.cs
- SslStream.cs
- XPathSingletonIterator.cs
- XamlBrushSerializer.cs
- SecureConversationServiceCredential.cs
- BehaviorService.cs
- LocalizabilityAttribute.cs
- TextStore.cs
- IISMapPath.cs
- Crypto.cs
- TableRowCollection.cs
- ResourceReader.cs
- RadioButton.cs
- RectangleF.cs
- SafeFindHandle.cs
- StateDesigner.TransitionInfo.cs
- WebBrowserNavigatingEventHandler.cs
- Grant.cs
- SqlTriggerAttribute.cs
- TagNameToTypeMapper.cs
- Action.cs
- DescendantBaseQuery.cs
- XmlNavigatorFilter.cs
- WindowsListViewGroupHelper.cs
- SiteIdentityPermission.cs
- StringComparer.cs
- PointKeyFrameCollection.cs
- BrowserInteropHelper.cs
- FloaterParagraph.cs
- BaseTemplateBuildProvider.cs
- CancellationHandler.cs
- FormViewModeEventArgs.cs
- SpAudioStreamWrapper.cs
- OwnerDrawPropertyBag.cs
- NavigationCommands.cs
- PrintPreviewControl.cs
- LogArchiveSnapshot.cs
- ResourceWriter.cs
- ContextQuery.cs
- CodeDomSerializer.cs
- DefaultClaimSet.cs
- UrlRoutingModule.cs
- Crc32Helper.cs
- XsdBuildProvider.cs
- CodeBlockBuilder.cs
- DnsPermission.cs
- SubordinateTransaction.cs
- ValidatorUtils.cs
- OperatingSystem.cs
- PageStatePersister.cs
- FileSystemEventArgs.cs
- safemediahandle.cs
- XmlNode.cs
- OdbcUtils.cs
- ScriptControl.cs
- CompoundFileReference.cs
- Gdiplus.cs
- InheritanceService.cs
- SynchronizationFilter.cs
- SystemMulticastIPAddressInformation.cs
- RectangleConverter.cs
- Encoding.cs
- XmlNavigatorFilter.cs
- ListViewItemEventArgs.cs
- DispatcherHookEventArgs.cs
- UriTemplateLiteralQueryValue.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- SubtreeProcessor.cs
- QuerySettings.cs
- complextypematerializer.cs
- InfoCardTrace.cs
- CriticalFinalizerObject.cs
- QuaternionIndependentAnimationStorage.cs
- PersonalizationProvider.cs
- ListBox.cs
- VirtualDirectoryMapping.cs
- VectorAnimation.cs
- LOSFormatter.cs
- SqlBulkCopyColumnMappingCollection.cs
- XmlTextAttribute.cs
- CompressedStack.cs
- SynchronizationContext.cs
- PasswordBox.cs
- TreeIterators.cs
- HScrollProperties.cs
- Transactions.cs
- DictionaryCustomTypeDescriptor.cs
- XmlJsonWriter.cs
- SessionParameter.cs
- Int32Rect.cs
- TreeWalker.cs
- NullableDoubleSumAggregationOperator.cs
- DataBinding.cs
- StringToken.cs