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
- Module.cs
- wgx_render.cs
- OwnerDrawPropertyBag.cs
- SqlTrackingWorkflowInstance.cs
- GridViewDeletedEventArgs.cs
- TimeSpanConverter.cs
- MissingFieldException.cs
- MonikerBuilder.cs
- RequestQueue.cs
- AnyAllSearchOperator.cs
- RelationshipFixer.cs
- FragmentNavigationEventArgs.cs
- X509ChainElement.cs
- FrameworkTemplate.cs
- SystemWebCachingSectionGroup.cs
- ShellProvider.cs
- ResourcesGenerator.cs
- _OSSOCK.cs
- AsyncStreamReader.cs
- Validator.cs
- PermissionRequestEvidence.cs
- Stopwatch.cs
- KeyboardNavigation.cs
- StylusOverProperty.cs
- InfoCardTrace.cs
- ValidationPropertyAttribute.cs
- XmlAttributeProperties.cs
- UserControl.cs
- SymLanguageVendor.cs
- SqlCharStream.cs
- SequenceDesigner.cs
- ShimAsPublicXamlType.cs
- Inflater.cs
- WindowsFont.cs
- AssemblyFilter.cs
- MailWriter.cs
- CodeVariableDeclarationStatement.cs
- OdbcCommandBuilder.cs
- HtmlShim.cs
- CodeAttributeArgumentCollection.cs
- Column.cs
- LongValidatorAttribute.cs
- DragDropManager.cs
- ToolStripGrip.cs
- Matrix3DConverter.cs
- SystemIPAddressInformation.cs
- NamedPermissionSet.cs
- StylusCollection.cs
- MethodAccessException.cs
- SettingsBindableAttribute.cs
- WebControlsSection.cs
- TripleDESCryptoServiceProvider.cs
- OleDbError.cs
- ParsedAttributeCollection.cs
- SecurityDocument.cs
- ISessionStateStore.cs
- XamlToRtfParser.cs
- Compilation.cs
- Scanner.cs
- Page.cs
- NamedPermissionSet.cs
- ConnectionProviderAttribute.cs
- LoadedEvent.cs
- SafeNativeMethodsMilCoreApi.cs
- Crypto.cs
- ObjectListShowCommandsEventArgs.cs
- xmlsaver.cs
- CursorInteropHelper.cs
- IMembershipProvider.cs
- SimpleWebHandlerParser.cs
- HttpWebRequest.cs
- TextChangedEventArgs.cs
- BitSet.cs
- RootNamespaceAttribute.cs
- ToolStripSeparator.cs
- HttpModuleActionCollection.cs
- XamlInt32CollectionSerializer.cs
- PaintValueEventArgs.cs
- XmlBindingWorker.cs
- XmlUtilWriter.cs
- CacheEntry.cs
- ActivityScheduledQuery.cs
- EntryPointNotFoundException.cs
- DrawingVisualDrawingContext.cs
- EditorPartChrome.cs
- LabelLiteral.cs
- SystemDiagnosticsSection.cs
- ToolStripOverflowButton.cs
- CachedBitmap.cs
- MessageQueue.cs
- DataSourceDescriptorCollection.cs
- ServicePointManagerElement.cs
- TextLine.cs
- DisplayMemberTemplateSelector.cs
- FixedSOMContainer.cs
- ObjectListDataBindEventArgs.cs
- X509Certificate2Collection.cs
- GenericWebPart.cs
- DateTimeOffsetStorage.cs
- PeerToPeerException.cs