Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Reflection / Pointer.cs / 1305376 / Pointer.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //////////////////////////////////////////////////////////////////////////////// // // This is a wrapper class for Pointers // //[....] // // // // namespace System.Reflection { using System; using CultureInfo = System.Globalization.CultureInfo; using System.Runtime.Serialization; using System.Diagnostics.Contracts; [CLSCompliant(false)] [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Pointer: ISerializable { unsafe private void* _ptr; private RuntimeType _ptrType; private Pointer() {} [System.Security.SecurityCritical] // auto-generated private unsafe Pointer(SerializationInfo info, StreamingContext context) { _ptr = ((IntPtr)(info.GetValue("_ptr", typeof(IntPtr)))).ToPointer(); _ptrType = (RuntimeType)info.GetValue("_ptrType", typeof(RuntimeType)); } // This method will box an pointer. We save both the // value and the type so we can access it from the native code // during an Invoke. [System.Security.SecurityCritical] // auto-generated public static unsafe Object Box(void *ptr,Type type) { if (type == null) throw new ArgumentNullException("type"); if (!type.IsPointer) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); Contract.EndContractBlock(); RuntimeType rt = type as RuntimeType; if (rt == null) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr"); Pointer x = new Pointer(); x._ptr = ptr; x._ptrType = rt; return x; } // Returned the stored pointer. [System.Security.SecurityCritical] // auto-generated public static unsafe void* Unbox(Object ptr) { if (!(ptr is Pointer)) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); return ((Pointer)ptr)._ptr; } internal RuntimeType GetPointerType() { return _ptrType; } [System.Security.SecurityCritical] // auto-generated internal unsafe Object GetPointerValue() { return (IntPtr)_ptr; } #if FEATURE_SERIALIZATION [System.Security.SecurityCritical] unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("_ptr", new IntPtr(_ptr)); info.AddValue("_ptrType", _ptrType); } #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //////////////////////////////////////////////////////////////////////////////// // // This is a wrapper class for Pointers // //[....] // // // // namespace System.Reflection { using System; using CultureInfo = System.Globalization.CultureInfo; using System.Runtime.Serialization; using System.Diagnostics.Contracts; [CLSCompliant(false)] [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Pointer: ISerializable { unsafe private void* _ptr; private RuntimeType _ptrType; private Pointer() {} [System.Security.SecurityCritical] // auto-generated private unsafe Pointer(SerializationInfo info, StreamingContext context) { _ptr = ((IntPtr)(info.GetValue("_ptr", typeof(IntPtr)))).ToPointer(); _ptrType = (RuntimeType)info.GetValue("_ptrType", typeof(RuntimeType)); } // This method will box an pointer. We save both the // value and the type so we can access it from the native code // during an Invoke. [System.Security.SecurityCritical] // auto-generated public static unsafe Object Box(void *ptr,Type type) { if (type == null) throw new ArgumentNullException("type"); if (!type.IsPointer) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); Contract.EndContractBlock(); RuntimeType rt = type as RuntimeType; if (rt == null) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr"); Pointer x = new Pointer(); x._ptr = ptr; x._ptrType = rt; return x; } // Returned the stored pointer. [System.Security.SecurityCritical] // auto-generated public static unsafe void* Unbox(Object ptr) { if (!(ptr is Pointer)) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); return ((Pointer)ptr)._ptr; } internal RuntimeType GetPointerType() { return _ptrType; } [System.Security.SecurityCritical] // auto-generated internal unsafe Object GetPointerValue() { return (IntPtr)_ptr; } #if FEATURE_SERIALIZATION [System.Security.SecurityCritical] unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("_ptr", new IntPtr(_ptr)); info.AddValue("_ptrType", _ptrType); } #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VScrollBar.cs
- AdRotator.cs
- SynchronizationContextHelper.cs
- RuleConditionDialog.Designer.cs
- WeakReadOnlyCollection.cs
- XmlEnumAttribute.cs
- WindowsUpDown.cs
- hresults.cs
- AttachedAnnotation.cs
- FixedPageAutomationPeer.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- SignatureToken.cs
- IOThreadScheduler.cs
- PaperSource.cs
- ServiceObjectContainer.cs
- SpeechRecognizer.cs
- RootBrowserWindowProxy.cs
- ResourceSetExpression.cs
- LogReserveAndAppendState.cs
- HotSpotCollection.cs
- ActiveXContainer.cs
- Grant.cs
- XmlReader.cs
- PersonalizationState.cs
- DataContractSerializerMessageContractImporter.cs
- EmbeddedObject.cs
- UnsafeNativeMethods.cs
- TreeNode.cs
- BuildResult.cs
- AutomationElementCollection.cs
- initElementDictionary.cs
- BamlLocalizationDictionary.cs
- ScriptBehaviorDescriptor.cs
- BadImageFormatException.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- AbstractSvcMapFileLoader.cs
- ResolveMatches11.cs
- XsltArgumentList.cs
- CacheModeConverter.cs
- XamlStackWriter.cs
- IconHelper.cs
- OleStrCAMarshaler.cs
- TypeElement.cs
- ByteAnimation.cs
- PopupEventArgs.cs
- IdnElement.cs
- IRCollection.cs
- IssuanceLicense.cs
- WebPartEventArgs.cs
- OrderingQueryOperator.cs
- PasswordPropertyTextAttribute.cs
- DateTimeStorage.cs
- TextEncodedRawTextWriter.cs
- FormViewDesigner.cs
- SamlDelegatingWriter.cs
- DataTableMapping.cs
- safesecurityhelperavalon.cs
- ProfileServiceManager.cs
- ExecutionPropertyManager.cs
- SchemaHelper.cs
- XmlToDatasetMap.cs
- AnonymousIdentificationModule.cs
- ToolboxItemCollection.cs
- OrderPreservingSpoolingTask.cs
- DesignTimeVisibleAttribute.cs
- WsdlInspector.cs
- LineServicesRun.cs
- XamlReaderHelper.cs
- WorkflowPersistenceService.cs
- SpeakProgressEventArgs.cs
- CommonDialog.cs
- CorrelationValidator.cs
- DocobjHost.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- DesignerActionKeyboardBehavior.cs
- FixedSchema.cs
- ContextMenuAutomationPeer.cs
- GuidelineSet.cs
- SqlSupersetValidator.cs
- SafeArrayTypeMismatchException.cs
- XmlNamespaceDeclarationsAttribute.cs
- NewArrayExpression.cs
- DataSourceSelectArguments.cs
- DataGridViewCellParsingEventArgs.cs
- Queue.cs
- MethodCallExpression.cs
- SelectionChangedEventArgs.cs
- XhtmlBasicImageAdapter.cs
- SaveFileDialog.cs
- SqlCacheDependencyDatabaseCollection.cs
- ThrowHelper.cs
- ProfileGroupSettings.cs
- Window.cs
- XmlComment.cs
- ExtentJoinTreeNode.cs
- PeerEndPoint.cs
- DataColumnMappingCollection.cs
- UpdatePanelTriggerCollection.cs
- ConfigsHelper.cs
- MailSettingsSection.cs