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
- HttpsHostedTransportConfiguration.cs
- StringConverter.cs
- BindStream.cs
- SimpleBitVector32.cs
- DurableMessageDispatchInspector.cs
- SamlConditions.cs
- Pen.cs
- ArrayTypeMismatchException.cs
- InputProviderSite.cs
- SoapConverter.cs
- Effect.cs
- CompositeControl.cs
- UIServiceHelper.cs
- ConfigXmlAttribute.cs
- DefaultTextStore.cs
- DataGridViewRowStateChangedEventArgs.cs
- SafeLocalAllocation.cs
- DynamicILGenerator.cs
- TrackingMemoryStream.cs
- PanelStyle.cs
- HandledEventArgs.cs
- DbConnectionHelper.cs
- ScrollBar.cs
- InfoCardHelper.cs
- ServiceDescriptionContext.cs
- HostVisual.cs
- PaginationProgressEventArgs.cs
- ParenthesizePropertyNameAttribute.cs
- RowVisual.cs
- AnyReturnReader.cs
- ContextProperty.cs
- EntityContainerEmitter.cs
- HostVisual.cs
- OutputCacheProfile.cs
- TokenizerHelper.cs
- Atom10FeedFormatter.cs
- JavaScriptObjectDeserializer.cs
- Schedule.cs
- TextRangeEditTables.cs
- CodeAssignStatement.cs
- Matrix3DConverter.cs
- Gdiplus.cs
- DefaultWorkflowLoaderService.cs
- EventDescriptor.cs
- EventLevel.cs
- ContentType.cs
- DataGridViewButtonCell.cs
- AssemblyCollection.cs
- PointHitTestParameters.cs
- SapiAttributeParser.cs
- DefaultExpressionVisitor.cs
- SmiMetaData.cs
- EntityDataSourceChangingEventArgs.cs
- CompilerTypeWithParams.cs
- NumericPagerField.cs
- HtmlEmptyTagControlBuilder.cs
- BaseProcessor.cs
- PeerObject.cs
- DefaultBinder.cs
- UICuesEvent.cs
- SizeFConverter.cs
- SwitchAttribute.cs
- HitTestWithPointDrawingContextWalker.cs
- PixelFormat.cs
- WebPartCatalogAddVerb.cs
- GiveFeedbackEvent.cs
- ApplicationSettingsBase.cs
- FastEncoder.cs
- FixUpCollection.cs
- DynamicDocumentPaginator.cs
- ListDataBindEventArgs.cs
- PageCatalogPart.cs
- ContentOnlyMessage.cs
- SchemaMerger.cs
- ContainerActivationHelper.cs
- StoreItemCollection.Loader.cs
- MediaTimeline.cs
- RegisteredDisposeScript.cs
- CodeMemberEvent.cs
- Point3DConverter.cs
- MetadataPropertyCollection.cs
- Int32AnimationBase.cs
- HtmlTitle.cs
- TraceSection.cs
- TransportSecurityProtocolFactory.cs
- clipboard.cs
- MetaType.cs
- ItemChangedEventArgs.cs
- WebPageTraceListener.cs
- WindowHideOrCloseTracker.cs
- QueryRelOp.cs
- RoutedPropertyChangedEventArgs.cs
- FontFamilyValueSerializer.cs
- DelegatingTypeDescriptionProvider.cs
- RichTextBoxConstants.cs
- SynchronizationContext.cs
- X509Certificate2.cs
- LongTypeConverter.cs
- CodeConstructor.cs
- SortDescriptionCollection.cs