Code:
/ FX-1434 / FX-1434 / 1.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
- ContextToken.cs
- StrokeCollection.cs
- WebPartHeaderCloseVerb.cs
- CommentAction.cs
- DrawingVisualDrawingContext.cs
- SqlDataSourceCache.cs
- XmlSchemaException.cs
- RegistryPermission.cs
- ColumnResizeAdorner.cs
- AddInAttribute.cs
- DocumentNUp.cs
- LogSwitch.cs
- SqlEnums.cs
- BuildTopDownAttribute.cs
- PerformanceCounter.cs
- DuplicateMessageDetector.cs
- ThreadStartException.cs
- COM2EnumConverter.cs
- SqlSelectClauseBuilder.cs
- CqlErrorHelper.cs
- TabItemWrapperAutomationPeer.cs
- hebrewshape.cs
- BaseResourcesBuildProvider.cs
- PopOutPanel.cs
- Pair.cs
- TextElement.cs
- WaitingCursor.cs
- DataTransferEventArgs.cs
- MenuAdapter.cs
- OracleTimeSpan.cs
- MessageProtectionOrder.cs
- XmlJsonWriter.cs
- Function.cs
- TextDecorationCollection.cs
- CqlGenerator.cs
- WebPartEventArgs.cs
- DataServiceRequestException.cs
- AffineTransform3D.cs
- HelpEvent.cs
- PresentationAppDomainManager.cs
- ChtmlFormAdapter.cs
- SqlBuilder.cs
- TableLayoutColumnStyleCollection.cs
- ResourceDictionary.cs
- ListSourceHelper.cs
- _LocalDataStoreMgr.cs
- WorkflowRuntimeServiceElementCollection.cs
- WebHttpBindingCollectionElement.cs
- ReflectTypeDescriptionProvider.cs
- LOSFormatter.cs
- EdmError.cs
- AuthenticationException.cs
- _DynamicWinsockMethods.cs
- milexports.cs
- Line.cs
- KnownTypesHelper.cs
- Tuple.cs
- CounterSample.cs
- RadioButton.cs
- FontTypeConverter.cs
- CheckBoxRenderer.cs
- OutOfProcStateClientManager.cs
- ColorComboBox.cs
- WebFormDesignerActionService.cs
- SamlAudienceRestrictionCondition.cs
- PrimitiveList.cs
- XmlWriterTraceListener.cs
- WindowsToolbar.cs
- ComAwareEventInfo.cs
- Int32Storage.cs
- CodeAttributeDeclaration.cs
- SchemaSetCompiler.cs
- PointF.cs
- ProtocolsSection.cs
- RootAction.cs
- RichTextBoxAutomationPeer.cs
- AmbientEnvironment.cs
- HexParser.cs
- DataListItemEventArgs.cs
- CollectionEditor.cs
- DateTimeUtil.cs
- ValidationErrorInfo.cs
- ControlDesigner.cs
- SqlFunctionAttribute.cs
- NameValueConfigurationCollection.cs
- UpDownBase.cs
- MappedMetaModel.cs
- EventRouteFactory.cs
- DocumentPage.cs
- BitHelper.cs
- Reference.cs
- IfElseDesigner.xaml.cs
- DefaultPrintController.cs
- ComplusTypeValidator.cs
- FormViewDeleteEventArgs.cs
- DataTrigger.cs
- QfeChecker.cs
- HostingEnvironment.cs
- IndentedTextWriter.cs
- BindingMemberInfo.cs