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
- ScriptServiceAttribute.cs
- MemoryStream.cs
- ReadWriteObjectLock.cs
- ColorDialog.cs
- RectIndependentAnimationStorage.cs
- Deflater.cs
- CommonObjectSecurity.cs
- StorageConditionPropertyMapping.cs
- SplineKeyFrames.cs
- EventLogEntry.cs
- HitTestParameters.cs
- NativeMethods.cs
- Animatable.cs
- DefaultShape.cs
- XmlSchemaExternal.cs
- BamlLocalizer.cs
- MasterPageParser.cs
- coordinatorscratchpad.cs
- Resources.Designer.cs
- IntSecurity.cs
- CollectionCodeDomSerializer.cs
- SHA256Cng.cs
- ResourceType.cs
- ToolStripTextBox.cs
- StrokeNodeEnumerator.cs
- ResourceIDHelper.cs
- StrokeNodeEnumerator.cs
- SizeIndependentAnimationStorage.cs
- XpsFontSubsetter.cs
- itemelement.cs
- RegistryKey.cs
- AsyncStreamReader.cs
- CompiledRegexRunnerFactory.cs
- AssemblyResolver.cs
- Nullable.cs
- ReverseInheritProperty.cs
- ConfigurationStrings.cs
- Dispatcher.cs
- Maps.cs
- SecurityVerifiedMessage.cs
- AdornerLayer.cs
- XpsStructure.cs
- CustomValidator.cs
- ServiceDescriptionData.cs
- RIPEMD160Managed.cs
- MessageSecurityOverTcpElement.cs
- EncodingInfo.cs
- FtpWebRequest.cs
- ListViewInsertEventArgs.cs
- HybridDictionary.cs
- PopupControlService.cs
- LayoutInformation.cs
- unitconverter.cs
- MetabaseReader.cs
- QueryFunctions.cs
- DoubleUtil.cs
- ListViewGroup.cs
- precedingsibling.cs
- SmtpReplyReaderFactory.cs
- COM2PictureConverter.cs
- SourceFileInfo.cs
- CollectionViewGroup.cs
- invalidudtexception.cs
- BitmapEffectGeneralTransform.cs
- Utils.cs
- StructuredTypeEmitter.cs
- Win32Exception.cs
- MimeMapping.cs
- MediaCommands.cs
- ConfigurationLocation.cs
- DBSqlParser.cs
- EdmScalarPropertyAttribute.cs
- RegisteredArrayDeclaration.cs
- HttpCapabilitiesEvaluator.cs
- Dump.cs
- TextDocumentView.cs
- _RequestCacheProtocol.cs
- Semaphore.cs
- NativeMethods.cs
- SQLMembershipProvider.cs
- TypeConverterAttribute.cs
- RequestCachePolicyConverter.cs
- SmiContextFactory.cs
- RegexInterpreter.cs
- StringAttributeCollection.cs
- DelegatingStream.cs
- TrimSurroundingWhitespaceAttribute.cs
- DataTableMapping.cs
- PeerNameResolver.cs
- TextTreeTextNode.cs
- FirstMatchCodeGroup.cs
- DocumentPage.cs
- Byte.cs
- BitVector32.cs
- Journal.cs
- DataBoundControlHelper.cs
- Timer.cs
- dataprotectionpermission.cs
- WindowPattern.cs
- WorkflowFormatterBehavior.cs