Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / __ComObject.cs / 1305376 / __ComObject.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: __ComObject
**
**
** __ComObject is the root class for all COM wrappers. This class
** defines only the basics. This class is used for wrapping COM objects
** accessed from COM+
**
**
===========================================================*/
namespace System {
using System;
using System.Collections;
using System.Threading;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security.Permissions;
internal class __ComObject : MarshalByRefObject
{
private Hashtable m_ObjectToDataMap;
/*===========================================================
** default constructor
** can't instantiate this directly
=============================================================*/
private __ComObject ()
{
}
[System.Security.SecurityCritical] // auto-generated
internal IntPtr GetIUnknown(out bool fIsURTAggregated)
{
fIsURTAggregated = !GetType().IsDefined(typeof(ComImportAttribute), false);
return System.Runtime.InteropServices.Marshal.GetIUnknownForObject(this);
}
//===================================================================
// This method retrieves the data associated with the specified
// key if any such data exists for the current __ComObject.
//===================================================================
internal Object GetData(Object key)
{
Object data = null;
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated, then there can be no data for the specified key.
if (m_ObjectToDataMap != null)
{
// Look up the data in the map.
data = m_ObjectToDataMap[key];
}
}
return data;
}
//====================================================================
// This method sets the data for the specified key on the current
// __ComObject.
//===================================================================
internal bool SetData(Object key, Object data)
{
bool bAdded = false;
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated yet, allocate it.
if (m_ObjectToDataMap == null)
m_ObjectToDataMap = new Hashtable();
// If there isn't already data in the map then add it.
if (m_ObjectToDataMap[key] == null)
{
m_ObjectToDataMap[key] = data;
bAdded = true;
}
}
return bAdded;
}
//====================================================================
// This method is called from within the EE and releases all the
// cached data for the __ComObject.
//====================================================================
[System.Security.SecurityCritical] // auto-generated
internal void ReleaseAllData()
{
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated, then there is nothing to do.
if (m_ObjectToDataMap != null)
{
foreach (Object o in m_ObjectToDataMap.Values)
{
// If the object implements IDisposable, then call Dispose on it.
IDisposable DisposableObj = o as IDisposable;
if (DisposableObj != null)
DisposableObj.Dispose();
// If the object is a derived from __ComObject, then call Marshal.ReleaseComObject on it.
__ComObject ComObj = o as __ComObject;
if (ComObj != null)
Marshal.ReleaseComObject(ComObj);
}
// Set the map to null to indicate it has been cleaned up.
m_ObjectToDataMap = null;
}
}
}
//===================================================================
// This method is called from within the EE and is used to handle
// calls on methods of event interfaces.
//====================================================================
[System.Security.SecurityCritical] // auto-generated
internal Object GetEventProvider(RuntimeType t)
{
// Check to see if we already have a cached event provider for this type.
Object EvProvider = GetData(t);
// If we don't then we need to create one.
if (EvProvider == null)
EvProvider = CreateEventProvider(t);
return EvProvider;
}
[System.Security.SecurityCritical] // auto-generated
internal int ReleaseSelf()
{
return Marshal.InternalReleaseComObject(this);
}
[System.Security.SecurityCritical] // auto-generated
internal void FinalReleaseSelf()
{
Marshal.InternalFinalReleaseComObject(this);
}
[System.Security.SecurityCritical] // auto-generated
[ReflectionPermissionAttribute(SecurityAction.Assert, MemberAccess=true)]
private Object CreateEventProvider(RuntimeType t)
{
// Create the event provider for the specified type.
Object EvProvider = Activator.CreateInstance(t, Activator.ConstructorDefault | BindingFlags.NonPublic, null, new Object[]{this}, null);
// Attempt to cache the wrapper on the object.
if (!SetData(t, EvProvider))
{
// Dispose the event provider if it implements IDisposable.
IDisposable DisposableEvProv = EvProvider as IDisposable;
if (DisposableEvProv != null)
DisposableEvProv.Dispose();
// Another thead already cached the wrapper so use that one instead.
EvProvider = GetData(t);
}
return EvProvider;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: __ComObject
**
**
** __ComObject is the root class for all COM wrappers. This class
** defines only the basics. This class is used for wrapping COM objects
** accessed from COM+
**
**
===========================================================*/
namespace System {
using System;
using System.Collections;
using System.Threading;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security.Permissions;
internal class __ComObject : MarshalByRefObject
{
private Hashtable m_ObjectToDataMap;
/*===========================================================
** default constructor
** can't instantiate this directly
=============================================================*/
private __ComObject ()
{
}
[System.Security.SecurityCritical] // auto-generated
internal IntPtr GetIUnknown(out bool fIsURTAggregated)
{
fIsURTAggregated = !GetType().IsDefined(typeof(ComImportAttribute), false);
return System.Runtime.InteropServices.Marshal.GetIUnknownForObject(this);
}
//===================================================================
// This method retrieves the data associated with the specified
// key if any such data exists for the current __ComObject.
//===================================================================
internal Object GetData(Object key)
{
Object data = null;
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated, then there can be no data for the specified key.
if (m_ObjectToDataMap != null)
{
// Look up the data in the map.
data = m_ObjectToDataMap[key];
}
}
return data;
}
//====================================================================
// This method sets the data for the specified key on the current
// __ComObject.
//===================================================================
internal bool SetData(Object key, Object data)
{
bool bAdded = false;
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated yet, allocate it.
if (m_ObjectToDataMap == null)
m_ObjectToDataMap = new Hashtable();
// If there isn't already data in the map then add it.
if (m_ObjectToDataMap[key] == null)
{
m_ObjectToDataMap[key] = data;
bAdded = true;
}
}
return bAdded;
}
//====================================================================
// This method is called from within the EE and releases all the
// cached data for the __ComObject.
//====================================================================
[System.Security.SecurityCritical] // auto-generated
internal void ReleaseAllData()
{
// Synchronize access to the map.
lock(this)
{
// If the map hasn't been allocated, then there is nothing to do.
if (m_ObjectToDataMap != null)
{
foreach (Object o in m_ObjectToDataMap.Values)
{
// If the object implements IDisposable, then call Dispose on it.
IDisposable DisposableObj = o as IDisposable;
if (DisposableObj != null)
DisposableObj.Dispose();
// If the object is a derived from __ComObject, then call Marshal.ReleaseComObject on it.
__ComObject ComObj = o as __ComObject;
if (ComObj != null)
Marshal.ReleaseComObject(ComObj);
}
// Set the map to null to indicate it has been cleaned up.
m_ObjectToDataMap = null;
}
}
}
//===================================================================
// This method is called from within the EE and is used to handle
// calls on methods of event interfaces.
//====================================================================
[System.Security.SecurityCritical] // auto-generated
internal Object GetEventProvider(RuntimeType t)
{
// Check to see if we already have a cached event provider for this type.
Object EvProvider = GetData(t);
// If we don't then we need to create one.
if (EvProvider == null)
EvProvider = CreateEventProvider(t);
return EvProvider;
}
[System.Security.SecurityCritical] // auto-generated
internal int ReleaseSelf()
{
return Marshal.InternalReleaseComObject(this);
}
[System.Security.SecurityCritical] // auto-generated
internal void FinalReleaseSelf()
{
Marshal.InternalFinalReleaseComObject(this);
}
[System.Security.SecurityCritical] // auto-generated
[ReflectionPermissionAttribute(SecurityAction.Assert, MemberAccess=true)]
private Object CreateEventProvider(RuntimeType t)
{
// Create the event provider for the specified type.
Object EvProvider = Activator.CreateInstance(t, Activator.ConstructorDefault | BindingFlags.NonPublic, null, new Object[]{this}, null);
// Attempt to cache the wrapper on the object.
if (!SetData(t, EvProvider))
{
// Dispose the event provider if it implements IDisposable.
IDisposable DisposableEvProv = EvProvider as IDisposable;
if (DisposableEvProv != null)
DisposableEvProv.Dispose();
// Another thead already cached the wrapper so use that one instead.
EvProvider = GetData(t);
}
return EvProvider;
}
}
}
// 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
- AddInBase.cs
- CanonicalFontFamilyReference.cs
- NativeObjectSecurity.cs
- GridPatternIdentifiers.cs
- ImmutableObjectAttribute.cs
- GridItemCollection.cs
- DataGridColumnCollection.cs
- DrawListViewItemEventArgs.cs
- HttpCapabilitiesBase.cs
- GroupQuery.cs
- FunctionImportMapping.cs
- GroupBoxRenderer.cs
- ServerValidateEventArgs.cs
- _ConnectOverlappedAsyncResult.cs
- WindowsScroll.cs
- Button.cs
- StringArrayEditor.cs
- ReadOnlyTernaryTree.cs
- CodeTypeConstructor.cs
- LinkButton.cs
- TemplatedWizardStep.cs
- QuaternionAnimation.cs
- SqlNamer.cs
- SpellerInterop.cs
- InvalidPrinterException.cs
- DbDataAdapter.cs
- ReturnType.cs
- XamlParser.cs
- NativeBuffer.cs
- ZipPackage.cs
- dtdvalidator.cs
- AnnotationResource.cs
- HostedController.cs
- ComplexBindingPropertiesAttribute.cs
- OracleParameter.cs
- MatrixTransform.cs
- EncodingDataItem.cs
- XmlElement.cs
- VectorConverter.cs
- TextBoxView.cs
- XmlTextReaderImpl.cs
- HtmlTableCellCollection.cs
- UnsafeNativeMethods.cs
- DNS.cs
- SystemDiagnosticsSection.cs
- StringSorter.cs
- CodeStatementCollection.cs
- TabItemAutomationPeer.cs
- ToolStripContainerActionList.cs
- TextRunCacheImp.cs
- CodeTypeDeclarationCollection.cs
- FlowDocumentReader.cs
- MailFileEditor.cs
- DebugViewWriter.cs
- BindingCollection.cs
- ConfigurationStrings.cs
- GeneralTransform3DGroup.cs
- ObjectConverter.cs
- ForceCopyBuildProvider.cs
- controlskin.cs
- Propagator.JoinPropagator.cs
- PersonalizationAdministration.cs
- MatrixAnimationUsingKeyFrames.cs
- Selection.cs
- CfgParser.cs
- smtppermission.cs
- Condition.cs
- BufferCache.cs
- SimplePropertyEntry.cs
- MaskedTextBox.cs
- IsolatedStoragePermission.cs
- XslException.cs
- ArrayMergeHelper.cs
- MediaElementAutomationPeer.cs
- JpegBitmapDecoder.cs
- TextBoxBaseDesigner.cs
- Models.cs
- ListViewItemEventArgs.cs
- ScriptResourceAttribute.cs
- HTMLTextWriter.cs
- ComplexLine.cs
- DropSource.cs
- OnOperation.cs
- ListViewHitTestInfo.cs
- RestHandler.cs
- SRDisplayNameAttribute.cs
- XmlDownloadManager.cs
- SystemIPGlobalProperties.cs
- InstanceOwner.cs
- ManualResetEventSlim.cs
- PerformanceCounterPermissionEntryCollection.cs
- UserControlParser.cs
- GridViewSortEventArgs.cs
- TypeConverterHelper.cs
- sqlnorm.cs
- LongTypeConverter.cs
- RotateTransform3D.cs
- ConfigDefinitionUpdates.cs
- As.cs
- OperatingSystem.cs