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
- PagePropertiesChangingEventArgs.cs
- tooltip.cs
- DbConnectionOptions.cs
- DeploymentSectionCache.cs
- GeometryCollection.cs
- CommandCollectionEditor.cs
- PropertyDescriptor.cs
- TextureBrush.cs
- NotFiniteNumberException.cs
- WeakEventTable.cs
- ContextBase.cs
- ParentQuery.cs
- PageSetupDialog.cs
- StringUtil.cs
- WebPartDescriptionCollection.cs
- UntypedNullExpression.cs
- TrackPoint.cs
- DateTimeOffset.cs
- WebPartDescription.cs
- ExtendedTransformFactory.cs
- Activator.cs
- ZoneLinkButton.cs
- ComponentCache.cs
- Decimal.cs
- InternalControlCollection.cs
- TogglePattern.cs
- SystemIPInterfaceStatistics.cs
- MutableAssemblyCacheEntry.cs
- PersonalizationAdministration.cs
- MetafileHeaderWmf.cs
- SecurityResources.cs
- ToolStripStatusLabel.cs
- AttributeCollection.cs
- EntityContainerRelationshipSetEnd.cs
- WebServiceParameterData.cs
- AnnouncementInnerClientCD1.cs
- SharedRuntimeState.cs
- NonVisualControlAttribute.cs
- CodeTypeMember.cs
- ToolBarTray.cs
- SystemResourceHost.cs
- DefaultTextStoreTextComposition.cs
- hebrewshape.cs
- SafeEventLogReadHandle.cs
- HtmlTableCellCollection.cs
- SecurityPermission.cs
- SlotInfo.cs
- HttpDictionary.cs
- CharUnicodeInfo.cs
- SystemColorTracker.cs
- DbConnectionPool.cs
- Win32Native.cs
- TrackingWorkflowEventArgs.cs
- SimpleType.cs
- SessionSwitchEventArgs.cs
- Camera.cs
- QilTernary.cs
- FileSystemWatcher.cs
- Graphics.cs
- XmlReaderSettings.cs
- ClientBuildManager.cs
- SoundPlayerAction.cs
- SpStreamWrapper.cs
- DetailsViewModeEventArgs.cs
- EncoderNLS.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ColorConverter.cs
- SimpleType.cs
- MSG.cs
- BitmapEffectState.cs
- XmlAnyElementAttributes.cs
- CodeCastExpression.cs
- AlternateViewCollection.cs
- Attachment.cs
- SymbolEqualComparer.cs
- DataRow.cs
- OperatingSystem.cs
- VersionUtil.cs
- PropertyMapper.cs
- TextEditorContextMenu.cs
- ExpandedProjectionNode.cs
- ObjectCacheHost.cs
- MainMenu.cs
- WebBrowserDocumentCompletedEventHandler.cs
- GifBitmapDecoder.cs
- XsltInput.cs
- PointConverter.cs
- TemplatedMailWebEventProvider.cs
- ClientSponsor.cs
- DeclarativeCatalogPart.cs
- InvokeBinder.cs
- DataGridViewRowsAddedEventArgs.cs
- DataProtection.cs
- IPPacketInformation.cs
- InfoCardArgumentException.cs
- AutomationPatternInfo.cs
- SHA384.cs
- WasAdminWrapper.cs
- PopupRootAutomationPeer.cs
- ParamArrayAttribute.cs