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
- XmlSchemaProviderAttribute.cs
- DispatcherProcessingDisabled.cs
- ComAdminWrapper.cs
- BinHexEncoder.cs
- ObjectToIdCache.cs
- UndirectedGraph.cs
- NamespaceEmitter.cs
- TextBoxBase.cs
- TextServicesContext.cs
- HiddenField.cs
- PropertyMetadata.cs
- ListControlBuilder.cs
- WebReferenceCollection.cs
- Vector3DAnimationUsingKeyFrames.cs
- storagemappingitemcollection.viewdictionary.cs
- TemplateBindingExpressionConverter.cs
- Literal.cs
- ScrollBarRenderer.cs
- QueryInterceptorAttribute.cs
- ListControl.cs
- DataGridViewImageColumn.cs
- TemplatedWizardStep.cs
- EmbeddedObject.cs
- VirtualizedContainerService.cs
- IUnknownConstantAttribute.cs
- GridViewRowCollection.cs
- ConfigurationManagerHelperFactory.cs
- TraceSection.cs
- LockedAssemblyCache.cs
- BooleanToVisibilityConverter.cs
- RuleSettings.cs
- ObjectStorage.cs
- DesignerDataTableBase.cs
- SemanticKeyElement.cs
- PngBitmapDecoder.cs
- _KerberosClient.cs
- QuotedStringWriteStateInfo.cs
- DashStyles.cs
- MailWriter.cs
- NegationPusher.cs
- VisualBasicHelper.cs
- Calendar.cs
- ZipIOModeEnforcingStream.cs
- FontStyles.cs
- WebPartEditorCancelVerb.cs
- Quaternion.cs
- BindingGroup.cs
- EntityDataSourceQueryBuilder.cs
- ChangeTracker.cs
- UrlParameterWriter.cs
- CatalogPart.cs
- FixedSchema.cs
- QilTernary.cs
- WindowsTab.cs
- Symbol.cs
- RequestQueryParser.cs
- BooleanFunctions.cs
- DataGridRowHeader.cs
- ImageField.cs
- BulletDecorator.cs
- FlowLayout.cs
- CharUnicodeInfo.cs
- IHttpResponseInternal.cs
- SynchronizationValidator.cs
- RuntimeHelpers.cs
- SiteIdentityPermission.cs
- BridgeDataReader.cs
- InheritedPropertyChangedEventArgs.cs
- SerializationInfoEnumerator.cs
- DataGridViewMethods.cs
- JsonFaultDetail.cs
- EntityDataSourceDataSelection.cs
- JavaScriptSerializer.cs
- LinkedResourceCollection.cs
- TextureBrush.cs
- ModelItemDictionaryImpl.cs
- Visitors.cs
- OleDbStruct.cs
- XmlAttributeProperties.cs
- ServiceModelConfigurationSection.cs
- PixelFormatConverter.cs
- VScrollProperties.cs
- EncoderFallback.cs
- PersonalizationProvider.cs
- ExceptionHandlers.cs
- ContentWrapperAttribute.cs
- FixUp.cs
- MergablePropertyAttribute.cs
- FocusManager.cs
- NavigationProgressEventArgs.cs
- SchemaImporterExtensionsSection.cs
- EntityDataSourceConfigureObjectContext.cs
- MessageSecurityOverTcpElement.cs
- RowVisual.cs
- PropertyOverridesTypeEditor.cs
- WebServiceMethodData.cs
- RequestCacheEntry.cs
- FormatPage.cs
- MetadataPropertyAttribute.cs
- HttpHandlerActionCollection.cs