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
- BamlBinaryWriter.cs
- Rule.cs
- SwitchCase.cs
- GridViewCommandEventArgs.cs
- DotNetATv1WindowsLogEntrySerializer.cs
- SymDocumentType.cs
- CodeCompileUnit.cs
- EventLogInformation.cs
- CoreChannel.cs
- ThreadLocal.cs
- SiteMapNode.cs
- TimeSpanOrInfiniteConverter.cs
- StoreItemCollection.cs
- odbcmetadatacolumnnames.cs
- DataServiceException.cs
- ISCIIEncoding.cs
- CapabilitiesState.cs
- ChannelDemuxer.cs
- Identity.cs
- Inline.cs
- ParseNumbers.cs
- CodeNamespaceImportCollection.cs
- XamlToRtfParser.cs
- WebBrowsableAttribute.cs
- Rotation3DAnimationBase.cs
- CodeTypeReferenceExpression.cs
- EdgeProfileValidation.cs
- ContentType.cs
- EditorPartCollection.cs
- XmlDataSource.cs
- SingleAnimationBase.cs
- PropertyItem.cs
- Int32Rect.cs
- Policy.cs
- NativeRecognizer.cs
- OptimalTextSource.cs
- SQLConvert.cs
- CssStyleCollection.cs
- GridViewEditEventArgs.cs
- StorageInfo.cs
- DataBindingList.cs
- FactoryMaker.cs
- ReadOnlyDataSource.cs
- WebDisplayNameAttribute.cs
- HttpCapabilitiesSectionHandler.cs
- ParameterModifier.cs
- ApplicationGesture.cs
- _Rfc2616CacheValidators.cs
- StringAttributeCollection.cs
- XmlValidatingReader.cs
- ConstraintStruct.cs
- HostAdapter.cs
- HttpWriter.cs
- WebResourceUtil.cs
- DataServiceQueryProvider.cs
- SchemaNamespaceManager.cs
- CoTaskMemSafeHandle.cs
- SiteMapPath.cs
- ProcessModuleCollection.cs
- HtmlInputText.cs
- MarkupObject.cs
- XmlArrayItemAttributes.cs
- VarRemapper.cs
- Brush.cs
- SqlParameter.cs
- SpoolingTask.cs
- ImageFormat.cs
- SafeNativeMethods.cs
- ObjectCloneHelper.cs
- TextRenderer.cs
- CacheOutputQuery.cs
- GridViewPageEventArgs.cs
- WindowsTooltip.cs
- TextOptionsInternal.cs
- EditingScopeUndoUnit.cs
- ConfigXmlCDataSection.cs
- ParallelLoopState.cs
- EditingCoordinator.cs
- BindingContext.cs
- StrokeSerializer.cs
- DrawingCollection.cs
- InfiniteTimeSpanConverter.cs
- OrderPreservingMergeHelper.cs
- DocumentSchemaValidator.cs
- ControlAdapter.cs
- SqlOuterApplyReducer.cs
- PageRanges.cs
- ToolStripItemCollection.cs
- WebPermission.cs
- DataErrorValidationRule.cs
- DbMetaDataColumnNames.cs
- MasterPageBuildProvider.cs
- BamlBinaryReader.cs
- Deflater.cs
- WebPartPersonalization.cs
- LineGeometry.cs
- ChannelHandler.cs
- PostBackTrigger.cs
- _NegoStream.cs
- UIElement3D.cs