Code:
/ DotNET / DotNET / 8.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
- Pen.cs
- UnsafeNativeMethods.cs
- MultiBindingExpression.cs
- mactripleDES.cs
- ScrollBarRenderer.cs
- NonVisualControlAttribute.cs
- AutomationPropertyInfo.cs
- Model3DGroup.cs
- SubMenuStyle.cs
- AssemblyBuilder.cs
- Thread.cs
- SystemSounds.cs
- QueryResult.cs
- CornerRadius.cs
- AnnotationStore.cs
- MembershipSection.cs
- WindowsListBox.cs
- HtmlImageAdapter.cs
- HttpHeaderCollection.cs
- ConfigurationManagerHelperFactory.cs
- OutputCacheProviderCollection.cs
- ClientApiGenerator.cs
- XamlValidatingReader.cs
- DesignerSerializationVisibilityAttribute.cs
- TextDecoration.cs
- FixUp.cs
- ApplicationSecurityInfo.cs
- DataControlFieldCollection.cs
- OracleNumber.cs
- PersistenceProviderBehavior.cs
- InheritanceContextHelper.cs
- OleDbException.cs
- ResourceProviderFactory.cs
- SaveFileDialog.cs
- ObjectFullSpanRewriter.cs
- DataServiceRequest.cs
- DataIdProcessor.cs
- BitSet.cs
- SmtpReplyReader.cs
- CheckedListBox.cs
- WebBrowser.cs
- Win32KeyboardDevice.cs
- UserControlAutomationPeer.cs
- TransformerInfo.cs
- PrintingPermission.cs
- WizardStepBase.cs
- HwndSourceKeyboardInputSite.cs
- WebPartDisplayModeCancelEventArgs.cs
- AsyncInvokeContext.cs
- NamespaceList.cs
- SecurityState.cs
- ChtmlSelectionListAdapter.cs
- SQLBytes.cs
- GradientBrush.cs
- WizardStepCollectionEditor.cs
- DESCryptoServiceProvider.cs
- WebPartConnectVerb.cs
- DoubleAnimationBase.cs
- MouseWheelEventArgs.cs
- RoutingExtensionElement.cs
- UITypeEditor.cs
- RequiredFieldValidator.cs
- ColorMatrix.cs
- AutoGeneratedField.cs
- FloaterBaseParaClient.cs
- SingleAnimation.cs
- QuotedStringWriteStateInfo.cs
- SessionState.cs
- MenuCommandsChangedEventArgs.cs
- ToolStripPanelRow.cs
- DiscardableAttribute.cs
- sqlpipe.cs
- MailWebEventProvider.cs
- FrameworkElementFactory.cs
- InputMethodStateTypeInfo.cs
- SqlConnectionHelper.cs
- CompilerTypeWithParams.cs
- Geometry3D.cs
- CollectionChangeEventArgs.cs
- ArgumentNullException.cs
- XmlAttributeHolder.cs
- CTreeGenerator.cs
- ISAPIApplicationHost.cs
- BezierSegment.cs
- ObjectHelper.cs
- EventProviderBase.cs
- WithParamAction.cs
- DeobfuscatingStream.cs
- MetadataItem_Static.cs
- MessageQueueInstaller.cs
- TraceLog.cs
- Win32Exception.cs
- CompositeScriptReferenceEventArgs.cs
- EtwTrackingParticipant.cs
- ColorContext.cs
- TemplateBuilder.cs
- FileCodeGroup.cs
- XmlHierarchicalDataSourceView.cs
- TypeListConverter.cs
- LogArchiveSnapshot.cs