Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / UIAutomationClient / System / Windows / Automation / Condition.cs / 1305600 / Condition.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 10/14/2003 : BrendanM - Created
//
//---------------------------------------------------------------------------
// PRESHARP: In order to avoid generating warnings about unkown message numbers and unknown pragmas.
#pragma warning disable 1634, 1691
using System;
using MS.Internal.Automation;
using System.Windows.Automation;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace System.Windows.Automation
{
// Internal Class that wraps the IntPtr to the Node
internal sealed class SafeConditionMemoryHandle : SafeHandle
{
// Called by P/Invoke when returning SafeHandles
// (Also used by UiaCoreApi to create invalid handles.)
internal SafeConditionMemoryHandle()
: base(IntPtr.Zero, true)
{
}
// No need to provide a finalizer - SafeHandle's critical finalizer will
// call ReleaseHandle for you.
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
override protected bool ReleaseHandle()
{
Marshal.FreeCoTaskMem(handle);
return true;
}
// uiaCondition is one of the Uia condition structs - eg UiaCoreApi.UiaAndOrCondition
internal static SafeConditionMemoryHandle AllocateConditionHandle(object uiaCondition)
{
// Allocate SafeHandle first to avoid failure later.
SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle();
int size = Marshal.SizeOf(uiaCondition);
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
try { }
finally
{
IntPtr mem = Marshal.AllocCoTaskMem(size);
sh.SetHandle(mem);
}
Marshal.StructureToPtr(uiaCondition, sh.handle, false);
return sh;
}
// used by And/Or conditions to allocate an array of pointers to other conditions
internal static SafeConditionMemoryHandle AllocateConditionArrayHandle(Condition [] conditions)
{
// Allocate SafeHandle first to avoid failure later.
SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle();
int intPtrSize = Marshal.SizeOf(typeof(IntPtr));
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
try { }
finally
{
IntPtr mem = Marshal.AllocCoTaskMem(conditions.Length * intPtrSize);
sh.SetHandle(mem);
}
unsafe
// Suppress "Exposing unsafe code thru public interface" UiaCoreApi is trusted
#pragma warning suppress 56505
{
IntPtr* pdata = (IntPtr*)sh.handle;
for (int i = 0; i < conditions.Length; i++)
{
*pdata++ = conditions[i]._safeHandle.handle;
}
}
return sh;
}
// Can't pass null into an API that takes a SafeHandle - so using this instead...
internal static SafeConditionMemoryHandle NullHandle = new SafeConditionMemoryHandle();
}
///
/// Base type for conditions used by LogicalElementSearcher.
///
#if (INTERNAL_COMPILE)
internal abstract class Condition
#else
public abstract class Condition
#endif
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Internal ctor to prevent others from deriving from this class
internal Condition()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Public readonly fields & constants
//
//-----------------------------------------------------
#region Public readonly fields & constants
/// Condition object that always evaluates to true
public static readonly Condition TrueCondition = new BoolCondition(true);
/// Condition object that always evaluates to false
public static readonly Condition FalseCondition = new BoolCondition(false);
#endregion Public readonly fields & constants
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
internal void SetMarshalData(object uiaCondition)
{
// Takes one of the interop UiaCondition classes (from UiaCoreApi.cs), and allocs
// a SafeHandle with associated unmanaged memory - can then pass that to the UIA APIs.
_safeHandle = SafeConditionMemoryHandle.AllocateConditionHandle(uiaCondition);
}
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Fields
//
//------------------------------------------------------
#region Internal Fields
internal SafeConditionMemoryHandle _safeHandle;
#endregion Internal Fields
//-----------------------------------------------------
//
// Nested Classes
//
//-----------------------------------------------------
private class BoolCondition: Condition
{
internal BoolCondition(bool b)
{
SetMarshalData(new UiaCoreApi.UiaCondition(b ? UiaCoreApi.ConditionType.True : UiaCoreApi.ConditionType.False));
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 10/14/2003 : BrendanM - Created
//
//---------------------------------------------------------------------------
// PRESHARP: In order to avoid generating warnings about unkown message numbers and unknown pragmas.
#pragma warning disable 1634, 1691
using System;
using MS.Internal.Automation;
using System.Windows.Automation;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace System.Windows.Automation
{
// Internal Class that wraps the IntPtr to the Node
internal sealed class SafeConditionMemoryHandle : SafeHandle
{
// Called by P/Invoke when returning SafeHandles
// (Also used by UiaCoreApi to create invalid handles.)
internal SafeConditionMemoryHandle()
: base(IntPtr.Zero, true)
{
}
// No need to provide a finalizer - SafeHandle's critical finalizer will
// call ReleaseHandle for you.
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
override protected bool ReleaseHandle()
{
Marshal.FreeCoTaskMem(handle);
return true;
}
// uiaCondition is one of the Uia condition structs - eg UiaCoreApi.UiaAndOrCondition
internal static SafeConditionMemoryHandle AllocateConditionHandle(object uiaCondition)
{
// Allocate SafeHandle first to avoid failure later.
SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle();
int size = Marshal.SizeOf(uiaCondition);
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
try { }
finally
{
IntPtr mem = Marshal.AllocCoTaskMem(size);
sh.SetHandle(mem);
}
Marshal.StructureToPtr(uiaCondition, sh.handle, false);
return sh;
}
// used by And/Or conditions to allocate an array of pointers to other conditions
internal static SafeConditionMemoryHandle AllocateConditionArrayHandle(Condition [] conditions)
{
// Allocate SafeHandle first to avoid failure later.
SafeConditionMemoryHandle sh = new SafeConditionMemoryHandle();
int intPtrSize = Marshal.SizeOf(typeof(IntPtr));
RuntimeHelpers.PrepareConstrainedRegions(); // ensures that the following finally block is atomic
try { }
finally
{
IntPtr mem = Marshal.AllocCoTaskMem(conditions.Length * intPtrSize);
sh.SetHandle(mem);
}
unsafe
// Suppress "Exposing unsafe code thru public interface" UiaCoreApi is trusted
#pragma warning suppress 56505
{
IntPtr* pdata = (IntPtr*)sh.handle;
for (int i = 0; i < conditions.Length; i++)
{
*pdata++ = conditions[i]._safeHandle.handle;
}
}
return sh;
}
// Can't pass null into an API that takes a SafeHandle - so using this instead...
internal static SafeConditionMemoryHandle NullHandle = new SafeConditionMemoryHandle();
}
///
/// Base type for conditions used by LogicalElementSearcher.
///
#if (INTERNAL_COMPILE)
internal abstract class Condition
#else
public abstract class Condition
#endif
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Internal ctor to prevent others from deriving from this class
internal Condition()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Public readonly fields & constants
//
//-----------------------------------------------------
#region Public readonly fields & constants
/// Condition object that always evaluates to true
public static readonly Condition TrueCondition = new BoolCondition(true);
/// Condition object that always evaluates to false
public static readonly Condition FalseCondition = new BoolCondition(false);
#endregion Public readonly fields & constants
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
internal void SetMarshalData(object uiaCondition)
{
// Takes one of the interop UiaCondition classes (from UiaCoreApi.cs), and allocs
// a SafeHandle with associated unmanaged memory - can then pass that to the UIA APIs.
_safeHandle = SafeConditionMemoryHandle.AllocateConditionHandle(uiaCondition);
}
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Fields
//
//------------------------------------------------------
#region Internal Fields
internal SafeConditionMemoryHandle _safeHandle;
#endregion Internal Fields
//-----------------------------------------------------
//
// Nested Classes
//
//-----------------------------------------------------
private class BoolCondition: Condition
{
internal BoolCondition(bool b)
{
SetMarshalData(new UiaCoreApi.UiaCondition(b ? UiaCoreApi.ConditionType.True : UiaCoreApi.ConditionType.False));
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebPartDisplayMode.cs
- ISFTagAndGuidCache.cs
- GroupBoxAutomationPeer.cs
- DataSourceComponent.cs
- SpotLight.cs
- EnumUnknown.cs
- SamlAttribute.cs
- ReadOnlyDataSourceView.cs
- TrustManager.cs
- SqlTransaction.cs
- PeekCompletedEventArgs.cs
- ToolStripCollectionEditor.cs
- peersecuritysettings.cs
- XmlSchemaCompilationSettings.cs
- SpecialNameAttribute.cs
- ContainerParaClient.cs
- SoapExtensionImporter.cs
- HtmlTextArea.cs
- LicenseException.cs
- DataSourceHelper.cs
- MetadataExchangeBindings.cs
- ItemsPanelTemplate.cs
- DockPanel.cs
- PowerModeChangedEventArgs.cs
- Error.cs
- Utils.cs
- Part.cs
- ParentControlDesigner.cs
- XPathNodeIterator.cs
- NativeMethods.cs
- AcceleratedTokenProvider.cs
- EventOpcode.cs
- PerformanceCounterPermissionAttribute.cs
- SelectionUIService.cs
- StyleReferenceConverter.cs
- cookieexception.cs
- XmlAttributes.cs
- HtmlElementCollection.cs
- Vector.cs
- ThreadStateException.cs
- DES.cs
- GuidTagList.cs
- EdmToObjectNamespaceMap.cs
- ViewUtilities.cs
- XmlDocumentViewSchema.cs
- DeadCharTextComposition.cs
- DocumentAutomationPeer.cs
- PeerObject.cs
- PositiveTimeSpanValidator.cs
- MaterialGroup.cs
- SqlConnectionString.cs
- FontCacheUtil.cs
- SortedDictionary.cs
- ErrorFormatterPage.cs
- ApplicationTrust.cs
- ToolStripDropDown.cs
- RelationshipFixer.cs
- DropDownHolder.cs
- GenericPrincipal.cs
- LayoutEngine.cs
- newinstructionaction.cs
- DataGridSortCommandEventArgs.cs
- ClientTargetSection.cs
- AssertFilter.cs
- SafePEFileHandle.cs
- TypeNameConverter.cs
- ReadWriteObjectLock.cs
- TimeSpanParse.cs
- TypeName.cs
- DoubleUtil.cs
- SqlClientFactory.cs
- MasterPageParser.cs
- FolderBrowserDialog.cs
- PriorityBinding.cs
- EntityDataSourceSelectedEventArgs.cs
- FloatUtil.cs
- FrameworkReadOnlyPropertyMetadata.cs
- HtmlAnchor.cs
- HtmlInputCheckBox.cs
- MenuBase.cs
- SpeechSynthesizer.cs
- TransactionScope.cs
- SocketElement.cs
- RowUpdatedEventArgs.cs
- DotExpr.cs
- TreeNodeConverter.cs
- X509ImageLogo.cs
- CryptoProvider.cs
- MsmqEncryptionAlgorithm.cs
- SecureStringHasher.cs
- BamlLocalizableResourceKey.cs
- PerformanceCountersElement.cs
- BamlTreeNode.cs
- localization.cs
- MenuItem.cs
- DataSourceHelper.cs
- XmlSerializationWriter.cs
- ListContractAdapter.cs
- BitmapEffectDrawingContextWalker.cs
- WinEventQueueItem.cs