Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Reflection / Pointer.cs / 1 / 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; [CLSCompliant(false)] [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class Pointer: ISerializable { unsafe private void* _ptr; private Type _ptrType; private Pointer() {} private unsafe Pointer(SerializationInfo info, StreamingContext context) { _ptr = ((IntPtr)(info.GetValue("_ptr", typeof(IntPtr)))).ToPointer(); _ptrType = (Type)info.GetValue("_ptrType", typeof(Type)); } // 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. 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"); Pointer x = new Pointer(); x._ptr = ptr; x._ptrType = type; return x; } // Returned the stored pointer. public static unsafe void* Unbox(Object ptr) { if (!(ptr is Pointer)) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); return ((Pointer)ptr)._ptr; } internal Type GetPointerType() { return _ptrType; } internal unsafe Object GetPointerValue() { return (IntPtr)_ptr; } unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("_ptr", new IntPtr(_ptr)); info.AddValue("_ptrType", _ptrType); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FlowDocumentFormatter.cs
- TrustLevel.cs
- _LoggingObject.cs
- AuthenticateEventArgs.cs
- EditorPart.cs
- HttpAsyncResult.cs
- compensatingcollection.cs
- DateTimeOffsetStorage.cs
- DataGridLinkButton.cs
- BackgroundFormatInfo.cs
- MailDefinition.cs
- CompilerCollection.cs
- GestureRecognizer.cs
- Helpers.cs
- DataGridViewRowHeaderCell.cs
- QilInvoke.cs
- CngKeyBlobFormat.cs
- BinaryMethodMessage.cs
- TypeSystem.cs
- SqlConnectionPoolProviderInfo.cs
- SessionState.cs
- XmlStreamStore.cs
- MenuStrip.cs
- HtmlValidatorAdapter.cs
- HtmlInputImage.cs
- TemplateNodeContextMenu.cs
- ConfigurationValidatorAttribute.cs
- SpeakProgressEventArgs.cs
- streamingZipPartStream.cs
- MexTcpBindingElement.cs
- ScriptComponentDescriptor.cs
- MatrixUtil.cs
- WmiInstallComponent.cs
- FilterEventArgs.cs
- FunctionCommandText.cs
- Attributes.cs
- ContractMapping.cs
- TypeRestriction.cs
- OperandQuery.cs
- DataListItemEventArgs.cs
- FileVersionInfo.cs
- IdleTimeoutMonitor.cs
- RangeBaseAutomationPeer.cs
- PassportIdentity.cs
- SelectionEditor.cs
- ActivityTypeResolver.xaml.cs
- SessionStateSection.cs
- RichTextBox.cs
- ByteStack.cs
- VisualProxy.cs
- FirstQueryOperator.cs
- TableAdapterManagerNameHandler.cs
- DataKeyCollection.cs
- UInt16Storage.cs
- FunctionDescription.cs
- CheckBox.cs
- ImageIndexConverter.cs
- StoreConnection.cs
- PolyBezierSegmentFigureLogic.cs
- Italic.cs
- DesignerTransaction.cs
- TreeNodeCollection.cs
- _DisconnectOverlappedAsyncResult.cs
- EmptyControlCollection.cs
- SynchronizationContext.cs
- EncryptedXml.cs
- DesignerActionUIStateChangeEventArgs.cs
- TypedReference.cs
- DbProviderFactoriesConfigurationHandler.cs
- SmiEventStream.cs
- DataComponentMethodGenerator.cs
- XmlSchemaSimpleTypeList.cs
- BamlLocalizabilityResolver.cs
- Application.cs
- RequiredAttributeAttribute.cs
- ExtensibleSyndicationObject.cs
- SoapFormatExtensions.cs
- AuthenticationConfig.cs
- ToolStripPanelCell.cs
- QueuePathDialog.cs
- SortDescription.cs
- RelationshipEnd.cs
- InputScope.cs
- XmlQuerySequence.cs
- SortedList.cs
- BuildManagerHost.cs
- Lease.cs
- Brush.cs
- WebControlAdapter.cs
- EventArgs.cs
- MemoryRecordBuffer.cs
- XmlSchemaInclude.cs
- WebConfigurationHost.cs
- HatchBrush.cs
- TemplateKey.cs
- DataGridViewColumnCollection.cs
- CallbackException.cs
- TextEditorSpelling.cs
- SequenceDesigner.cs
- ObjectDataSourceMethodEditor.cs