Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Reflection / Emit / MethodRental.cs / 1305376 / 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.Runtime.Versioning; using System.Globalization; using System.Security; using System.Diagnostics.Contracts; // 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 [System.Security.SecuritySafeCritical] // auto-generated [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"); Contract.EndContractBlock(); Module module = cls.Module; InternalModuleBuilder internalMB; ModuleBuilder mb = module as ModuleBuilder; if (mb != null) internalMB = mb.InternalModule; else internalMB = module as InternalModuleBuilder; // can only swap method body on dynamic module // dynamic internal module type is always exactly InternalModuleBuilder, non-dynamic is always something different if (internalMB == null) 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(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; RuntimeAssembly rtAssembly = internalMB.GetRuntimeAssembly(); lock (rtAssembly.SyncRoot) { SwapMethodBody(rType.GetTypeHandleInternal(), methodtoken, rgIL, methodSize, flags, JitHelpers.GetStackCrawlMarkHandle(ref mark)); } } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void SwapMethodBody( RuntimeTypeHandle 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 StackCrawlMarkHandle 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
- HtmlInputFile.cs
- Quaternion.cs
- HttpHandlerAction.cs
- DynamicRenderer.cs
- EndpointInfoCollection.cs
- ReliableChannelBinder.cs
- StatusBar.cs
- ResourceDictionaryCollection.cs
- EntityReference.cs
- HttpTransportSecurity.cs
- CodeIdentifiers.cs
- QueryCoreOp.cs
- DbResourceAllocator.cs
- XhtmlBasicPhoneCallAdapter.cs
- ExpressionBuilder.cs
- ComboBoxAutomationPeer.cs
- WebServicesSection.cs
- ToolStripDropDownMenu.cs
- DataGridViewColumnTypeEditor.cs
- InitiatorServiceModelSecurityTokenRequirement.cs
- PageHandlerFactory.cs
- HatchBrush.cs
- ToolStripContentPanelDesigner.cs
- BufferBuilder.cs
- ToolStripPanel.cs
- XamlToRtfParser.cs
- InvalidAsynchronousStateException.cs
- EventDescriptorCollection.cs
- ProviderSettings.cs
- EventProxy.cs
- MembershipSection.cs
- SHA256.cs
- CacheChildrenQuery.cs
- ProfileServiceManager.cs
- DummyDataSource.cs
- CapabilitiesUse.cs
- SessionStateSection.cs
- Substitution.cs
- SpnEndpointIdentity.cs
- LostFocusEventManager.cs
- XmlSequenceWriter.cs
- TreeNodeClickEventArgs.cs
- EtwTrace.cs
- Odbc32.cs
- WebPartExportVerb.cs
- storepermission.cs
- MemberInfoSerializationHolder.cs
- BamlCollectionHolder.cs
- StandardCommands.cs
- SystemDropShadowChrome.cs
- InputLangChangeRequestEvent.cs
- OpenTypeCommon.cs
- DocumentSequence.cs
- DecoderFallbackWithFailureFlag.cs
- CommandConverter.cs
- DataGridViewColumnStateChangedEventArgs.cs
- ConvertEvent.cs
- ThreadAttributes.cs
- BufferedOutputStream.cs
- ResourceDefaultValueAttribute.cs
- WMIGenerator.cs
- SvcFileManager.cs
- ServiceNameElement.cs
- SHA1.cs
- Simplifier.cs
- SmtpDigestAuthenticationModule.cs
- EndpointDiscoveryMetadataCD1.cs
- UniqueEventHelper.cs
- DesigntimeLicenseContextSerializer.cs
- _UncName.cs
- DataGridBoolColumn.cs
- HandleValueEditor.cs
- EnvelopedPkcs7.cs
- _DynamicWinsockMethods.cs
- NetworkInterface.cs
- QueryContext.cs
- ListItemViewAttribute.cs
- ActivatableWorkflowsQueryResult.cs
- SpanIndex.cs
- SqlNodeAnnotations.cs
- FixedStringLookup.cs
- WorkflowApplication.cs
- SchemaContext.cs
- BooleanConverter.cs
- ElasticEase.cs
- RemotingClientProxy.cs
- MatrixTransform.cs
- DesigntimeLicenseContext.cs
- TableLayoutStyle.cs
- StreamGeometryContext.cs
- EndpointAddressProcessor.cs
- Message.cs
- SeekStoryboard.cs
- EntityModelBuildProvider.cs
- MarkedHighlightComponent.cs
- ProvidePropertyAttribute.cs
- DataGridViewRowCancelEventArgs.cs
- AsyncPostBackErrorEventArgs.cs
- ConfigurationValues.cs
- WebPartConnectionsConfigureVerb.cs