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
- MergeLocalizationDirectives.cs
- ScriptManager.cs
- QueryPageSettingsEventArgs.cs
- MouseEventArgs.cs
- ImageAttributes.cs
- RequestCache.cs
- Label.cs
- SQLMembershipProvider.cs
- BrowserCapabilitiesFactoryBase.cs
- ArrayConverter.cs
- BuilderInfo.cs
- HelpKeywordAttribute.cs
- LineServices.cs
- FixedSOMTable.cs
- LineProperties.cs
- ReliableRequestSessionChannel.cs
- CharacterBufferReference.cs
- StringStorage.cs
- CalendarDay.cs
- ListControlDesigner.cs
- CatalogPartCollection.cs
- ContextItemManager.cs
- TreeNodeBindingDepthConverter.cs
- ToolStripPanelRow.cs
- HttpFileCollection.cs
- RelationshipDetailsRow.cs
- CommandEventArgs.cs
- NonBatchDirectoryCompiler.cs
- XmlDataSourceNodeDescriptor.cs
- ProtocolsConfigurationEntry.cs
- SystemIPAddressInformation.cs
- InternalPolicyElement.cs
- DoubleAnimationClockResource.cs
- ModelItemCollection.cs
- CalendarSelectionChangedEventArgs.cs
- ResourceIDHelper.cs
- OlePropertyStructs.cs
- GlyphTypeface.cs
- DialogResultConverter.cs
- CookieParameter.cs
- StaticExtensionConverter.cs
- HtmlTextBoxAdapter.cs
- ExpandSegment.cs
- shaperfactoryquerycacheentry.cs
- FormsIdentity.cs
- mactripleDES.cs
- SmiGettersStream.cs
- XMLSyntaxException.cs
- MimeTypeMapper.cs
- DataGridViewColumnConverter.cs
- EdmRelationshipRoleAttribute.cs
- MediaContext.cs
- CodeBinaryOperatorExpression.cs
- DataGridViewMethods.cs
- FileDialogCustomPlaces.cs
- OpacityConverter.cs
- WindowsSolidBrush.cs
- SocketException.cs
- BlobPersonalizationState.cs
- NotifyIcon.cs
- Attachment.cs
- ContactManager.cs
- MetadataCollection.cs
- DesignerRegionMouseEventArgs.cs
- ClientTarget.cs
- XmlSerializerSection.cs
- MsmqIntegrationProcessProtocolHandler.cs
- HtmlInputReset.cs
- XamlTreeBuilder.cs
- DocumentPaginator.cs
- SetStoryboardSpeedRatio.cs
- XPathSingletonIterator.cs
- PolicyException.cs
- SystemInfo.cs
- FixedSOMImage.cs
- ObjectDataSourceView.cs
- _StreamFramer.cs
- BindingEntityInfo.cs
- CrossSiteScriptingValidation.cs
- SafeNativeMethods.cs
- FileInfo.cs
- UtilityExtension.cs
- DataGridViewRowCollection.cs
- ActivityTrace.cs
- CodeGeneratorOptions.cs
- Queue.cs
- RedBlackList.cs
- RawStylusSystemGestureInputReport.cs
- XmlAutoDetectWriter.cs
- IsolatedStorageException.cs
- SchemaConstraints.cs
- MetroSerializationManager.cs
- listitem.cs
- PropertyEmitter.cs
- HistoryEventArgs.cs
- String.cs
- DesignerDataSchemaClass.cs
- EndEvent.cs
- Variant.cs
- FixedElement.cs