Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RtfFormatStack.cs
- SplashScreenNativeMethods.cs
- SafeRightsManagementQueryHandle.cs
- XmlSchemaObject.cs
- ControlType.cs
- BamlLocalizationDictionary.cs
- SafeNativeMethods.cs
- PropertyCollection.cs
- DecoderReplacementFallback.cs
- MdImport.cs
- CheckBoxField.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- DataGridViewImageColumn.cs
- ApplicationManager.cs
- ValueConversionAttribute.cs
- XhtmlCssHandler.cs
- SqlServer2KCompatibilityAnnotation.cs
- PropertyConverter.cs
- SerialPinChanges.cs
- TextEvent.cs
- HttpValueCollection.cs
- XpsTokenContext.cs
- MsmqTransportSecurity.cs
- FlowThrottle.cs
- ControlUtil.cs
- WebPartZoneAutoFormat.cs
- FileSystemEventArgs.cs
- ProcessHostFactoryHelper.cs
- Terminate.cs
- AddDataControlFieldDialog.cs
- OperationPickerDialog.cs
- XmlChoiceIdentifierAttribute.cs
- KerberosReceiverSecurityToken.cs
- TextEncodedRawTextWriter.cs
- HitTestDrawingContextWalker.cs
- SecurityCookieModeValidator.cs
- XmlSchemaCollection.cs
- ChannelDispatcherBase.cs
- ApplicationSettingsBase.cs
- HttpModulesSection.cs
- GeometryModel3D.cs
- RelationshipEndCollection.cs
- NullableDoubleSumAggregationOperator.cs
- WorkflowViewService.cs
- NumericUpDownAcceleration.cs
- _WinHttpWebProxyDataBuilder.cs
- DataViewSetting.cs
- GradientStop.cs
- BindingParameterCollection.cs
- ClientEventManager.cs
- BindableTemplateBuilder.cs
- FloaterParagraph.cs
- SiteMapPath.cs
- GenericXmlSecurityToken.cs
- ParserStreamGeometryContext.cs
- InteropExecutor.cs
- XmlAttributeCache.cs
- WebBrowsableAttribute.cs
- HttpCookieCollection.cs
- LicenseManager.cs
- AutomationProperties.cs
- ExpressionBuilder.cs
- RowSpanVector.cs
- StaticDataManager.cs
- Annotation.cs
- GenericsInstances.cs
- OverflowException.cs
- BaseDataList.cs
- TreeNodeStyle.cs
- PixelShader.cs
- Baml2006ReaderContext.cs
- QueryTask.cs
- XmlSchemas.cs
- RelatedCurrencyManager.cs
- SafeNativeMethods.cs
- MembershipValidatePasswordEventArgs.cs
- SqlDataSourceQueryEditorForm.cs
- XdrBuilder.cs
- SystemIPGlobalProperties.cs
- UIInitializationException.cs
- TraceHandlerErrorFormatter.cs
- UnmanagedMemoryStream.cs
- SplitterCancelEvent.cs
- ListItemCollection.cs
- ToggleButtonAutomationPeer.cs
- BitmapCodecInfoInternal.cs
- SerializationInfoEnumerator.cs
- VBIdentifierDesigner.xaml.cs
- FileNotFoundException.cs
- SmtpClient.cs
- InvalidPrinterException.cs
- WmlLiteralTextAdapter.cs
- DBPropSet.cs
- LabelLiteral.cs
- UInt64.cs
- FormatterConverter.cs
- HtmlAnchor.cs
- DataServiceQueryProvider.cs
- Operand.cs
- LambdaCompiler.Unary.cs