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
- ChangePasswordAutoFormat.cs
- input.cs
- ResolveNameEventArgs.cs
- ClientTargetSection.cs
- BindingBase.cs
- ConversionValidationRule.cs
- TextBoxRenderer.cs
- DescendantQuery.cs
- HitTestParameters.cs
- Int32Rect.cs
- ConnectionStringsExpressionBuilder.cs
- DbProviderServices.cs
- SizeAnimationUsingKeyFrames.cs
- InheritedPropertyChangedEventArgs.cs
- SqlDataSourceSelectingEventArgs.cs
- SafeCryptoHandles.cs
- infer.cs
- CryptoStream.cs
- DefaultBindingPropertyAttribute.cs
- TreeWalker.cs
- CacheAxisQuery.cs
- CallbackException.cs
- ConfigurationElementProperty.cs
- XmlElementCollection.cs
- ProcessHost.cs
- XXXInfos.cs
- FormClosedEvent.cs
- EntityProviderServices.cs
- ProxySimple.cs
- DesignerOptionService.cs
- RewritingSimplifier.cs
- PrimitiveXmlSerializers.cs
- NgenServicingAttributes.cs
- XmlAttributes.cs
- Process.cs
- VisualStyleTypesAndProperties.cs
- UnSafeCharBuffer.cs
- TextTreeObjectNode.cs
- EventLogger.cs
- EntitySqlQueryState.cs
- ModuleBuilder.cs
- XmlEntity.cs
- StringCollection.cs
- OledbConnectionStringbuilder.cs
- WebConfigurationHost.cs
- CallSite.cs
- ToolStripPanelRow.cs
- EntityDataSourceView.cs
- DetailsView.cs
- DataKey.cs
- DocumentOutline.cs
- CaseInsensitiveComparer.cs
- CryptoApi.cs
- CompilerResults.cs
- ProxyWebPartManager.cs
- XamlPoint3DCollectionSerializer.cs
- SchemaSetCompiler.cs
- PriorityQueue.cs
- Point3DKeyFrameCollection.cs
- XmlSchemaComplexContent.cs
- ErrorItem.cs
- PackagePartCollection.cs
- StringDictionaryCodeDomSerializer.cs
- DataException.cs
- CommunicationObjectFaultedException.cs
- ServiceParser.cs
- ServiceSecurityContext.cs
- HMACMD5.cs
- WebServiceMethodData.cs
- SmiEventSink.cs
- AdRotator.cs
- XmlSchemaType.cs
- unsafeIndexingFilterStream.cs
- unitconverter.cs
- ErrorTableItemStyle.cs
- EncryptedKeyIdentifierClause.cs
- LoginNameDesigner.cs
- GridViewCancelEditEventArgs.cs
- FacetValues.cs
- ScaleTransform.cs
- GlobalProxySelection.cs
- WebPartManagerInternals.cs
- UpDownBase.cs
- QilExpression.cs
- Bidi.cs
- WebPartAuthorizationEventArgs.cs
- CompoundFileDeflateTransform.cs
- ColorIndependentAnimationStorage.cs
- ThreadPool.cs
- MaxValueConverter.cs
- PersonalizationProvider.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- RequestCacheValidator.cs
- DbParameterCollectionHelper.cs
- EdmType.cs
- DBConnectionString.cs
- PageContent.cs
- MouseActionValueSerializer.cs
- AsymmetricSignatureFormatter.cs
- TabControlEvent.cs