未验证 提交 0bb367cb 编写于 作者: T ThomasGoulet73 提交者: GitHub

Replace resource constants with properties in UIAutomationClient (#6620)

Contributes to dotnet/wpf#1
Co-authored-by: NDipesh Kumar <85861525+dipeshmsft@users.noreply.github.com>
上级 4256bf2a
......@@ -12,6 +12,7 @@
<_GenerateResourcesCodeAsConstants>true</_GenerateResourcesCodeAsConstants>
<_GenerateResourcesCodeAsConstants Condition="'$(MSBuildProjectName)'=='UIAutomationClient'">false</_GenerateResourcesCodeAsConstants>
<_GenerateResourcesCodeAsConstants Condition="'$(MSBuildProjectName)'=='UIAutomationProvider'">false</_GenerateResourcesCodeAsConstants>
<_GenerateResourcesCodeAsConstants Condition="'$(MSBuildProjectName)'=='System.Xaml'">false</_GenerateResourcesCodeAsConstants>
<_GenerateResourcesCodeAsConstants Condition="'$(MSBuildProjectName)'=='WindowsBase'">false</_GenerateResourcesCodeAsConstants>
......@@ -30,6 +31,7 @@
<GenerateResourcesCodeAsConstants>$(_GenerateResourcesCodeAsConstants)</GenerateResourcesCodeAsConstants>
<ClassName Condition="'$(AssemblyName)'=='PresentationBuildTasks'">MS.Utility.SRID</ClassName>
<ClassName Condition="'$(AssemblyName)'=='UIAutomationClient'">System.SR</ClassName>
<ClassName Condition="'$(AssemblyName)'=='UIAutomationProvider'">MS.Internal.Automation.SR</ClassName>
<ClassName Condition="'$(AssemblyName)'=='UIAutomationTypes'">System.SR</ClassName>
<ClassName Condition="'$(AssemblyName)'=='WindowsBase'">MS.Internal.WindowsBase.SR</ClassName>
......
......@@ -307,7 +307,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
{
// you can't really do anything to a disabled window
if ( IsBitSet(GetWindowStyle(), SafeNativeMethods.WS_DISABLED) )
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
// If already in the normal state, do not need to do anything.
if (((IWindowProvider)this).VisualState == WindowVisualState.Normal)
......@@ -323,7 +323,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
// get the WINDOWPLACEMENT information
if (!Misc.GetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
wp.showCmd = UnsafeNativeMethods.SW_RESTORE;
......@@ -332,7 +332,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
// sending SC_RESTORE puts it back to maximized instead of normal.
if (!Misc.SetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
return;
......@@ -341,7 +341,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
case WindowVisualState.Minimized:
{
if (!((IWindowProvider)this).Minimizable)
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
// If already minimzed, do not need to do anything.
if (((IWindowProvider)this).VisualState == WindowVisualState.Minimized)
......@@ -353,7 +353,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
if (!Misc.PostMessage(_hwnd, UnsafeNativeMethods.WM_SYSCOMMAND, (IntPtr)UnsafeNativeMethods.SC_MINIMIZE, IntPtr.Zero))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
return;
......@@ -362,7 +362,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
case WindowVisualState.Maximized:
{
if ( ! ((IWindowProvider)this).Maximizable )
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
// If already maximized, do not need to do anything.
if (((IWindowProvider)this).VisualState == WindowVisualState.Maximized)
......@@ -374,7 +374,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
if (!Misc.PostMessage(_hwnd, UnsafeNativeMethods.WM_SYSCOMMAND, (IntPtr)UnsafeNativeMethods.SC_MAXIMIZE, IntPtr.Zero))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
return;
......@@ -383,7 +383,7 @@ void IWindowProvider.SetVisualState( WindowVisualState state )
default:
{
Debug.Assert(false,"unexpected switch() case:");
throw new ArgumentException(SR.Get(SRID.UnexpectedWindowState),"state");
throw new ArgumentException(SR.UnexpectedWindowState,"state");
}
}
......@@ -396,7 +396,7 @@ void IWindowProvider.Close()
if (!Misc.PostMessage(_hwnd, UnsafeNativeMethods.WM_SYSCOMMAND, (IntPtr)UnsafeNativeMethods.SC_CLOSE, IntPtr.Zero))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
......@@ -640,7 +640,7 @@ bool IWindowProvider.IsTopmost
void ITransformProvider.Move( double x, double y )
{
if ( ! ((ITransformProvider)this).CanMove )
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
int extendedStyle = GetWindowExStyle();
if ( IsBitSet(extendedStyle, SafeNativeMethods.WS_EX_MDICHILD) )
......@@ -651,7 +651,7 @@ void ITransformProvider.Move( double x, double y )
NativeMethods.HWND hwndParent = SafeNativeMethods.GetAncestor(NativeMethods.HWND.Cast(_hwnd), SafeNativeMethods.GA_PARENT);
if (!MapWindowPoints(NativeMethods.HWND.NULL, hwndParent, ref point, 1))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
x = point.x;
y = point.y;
......@@ -660,7 +660,7 @@ void ITransformProvider.Move( double x, double y )
NativeMethods.RECT currentRect = new NativeMethods.RECT();
if (!Misc.GetWindowRect(_hwnd, out currentRect))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
int currentHeight = currentRect.bottom - currentRect.top;
int currentWidth = currentRect.right - currentRect.left;
......@@ -684,7 +684,7 @@ void ITransformProvider.Move( double x, double y )
NativeMethods.RECT parentRect = new NativeMethods.RECT();
if (!Misc.GetClientRect(hwndParent, out parentRect))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// If to far to the right move left edge to be visible.
// Move the left edge back the diffance of it and the parent's client area right side plus a little more to be visible.
......@@ -706,7 +706,7 @@ void ITransformProvider.Move( double x, double y )
// putting the window in the wrong place
if (!Misc.SetWindowPos(_hwnd, NativeMethods.HWND.NULL, (int)x, (int)y, 0, 0, UnsafeNativeMethods.SWP_NOSIZE | UnsafeNativeMethods.SWP_NOZORDER | UnsafeNativeMethods.SWP_NOACTIVATE))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
UnsafeNativeMethods.WINDOWPLACEMENT wp = new UnsafeNativeMethods.WINDOWPLACEMENT();
......@@ -716,13 +716,13 @@ void ITransformProvider.Move( double x, double y )
// terms of the workarea.
if (!Misc.GetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
int style = GetWindowStyle();
if (style == 0)
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
if ( IsBitSet(style, SafeNativeMethods.WS_MINIMIZE) )
{
......@@ -736,7 +736,7 @@ void ITransformProvider.Move( double x, double y )
// it will place the window on the primary monitor at a location closest to the taget.
if (!Misc.SetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
else
......@@ -745,7 +745,7 @@ void ITransformProvider.Move( double x, double y )
if (!Misc.GetWindowRect(_hwnd, out currentRect))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// Use SetWindowPlacement to move the window because it handles the case where the
......@@ -753,7 +753,7 @@ void ITransformProvider.Move( double x, double y )
// it will place the window on the primary monitor at a location closest to the taget.
if (!Misc.SetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// check to make sure SetWindowPlacement has not changed the size of our window
......@@ -762,7 +762,7 @@ void ITransformProvider.Move( double x, double y )
if (!Misc.GetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
int newHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
......@@ -775,7 +775,7 @@ void ITransformProvider.Move( double x, double y )
if (!Misc.SetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
}
......@@ -790,7 +790,7 @@ void ITransformProvider.Resize( double width, double height )
int heightInt = (int) height;
if ( ! ((ITransformProvider)this).CanResize )
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
UnsafeNativeMethods.MINMAXINFO minMaxInfo = default;
......@@ -827,7 +827,7 @@ void ITransformProvider.Resize( double width, double height )
// get the WINDOWPLACEMENT information
if (!Misc.GetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// Calculate the new right and bottom for how the user wants the window resized and update the struct
......@@ -839,7 +839,7 @@ void ITransformProvider.Resize( double width, double height )
// it will place the window on the primary monitor at a location closes to the taget.
if (!Misc.SetWindowPlacement(_hwnd, ref wp))
{
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
......@@ -848,7 +848,7 @@ void ITransformProvider.Rotate( double degrees )
if (!SafeNativeMethods.IsWindow(_hwnd))
throw new ElementNotAvailableException();
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
bool ITransformProvider.CanMove
......
......@@ -149,7 +149,7 @@ internal static object WrapInterfaceOnClientSide(AutomationElement el, SafePatte
if (!Schema.GetPatternInfo(pattern, out pi))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedPattern));
throw new ArgumentException(SR.UnsupportedPattern);
}
if (pi.ClientSideWrapper == null)
......@@ -180,7 +180,7 @@ internal static void ValidateArgumentNonNull(object obj, string argName)
// Throw an argument Exception with a generic error
internal static void ThrowInvalidArgument(string argName)
{
throw new ArgumentException(SR.Get(SRID.GenericInvalidArgument, argName));
throw new ArgumentException(SR.Format(SR.GenericInvalidArgument, argName));
}
// Check that specified condition is true; if not, throw exception
......@@ -188,7 +188,7 @@ internal static void ValidateArgument(bool cond, string reason)
{
if (!cond)
{
throw new ArgumentException(SR.Get(reason));
throw new ArgumentException(SR.GetResourceString(reason, null));
}
}
......@@ -206,7 +206,7 @@ internal static void ValidateCached(bool cached)
{
if (!cached)
{
throw new InvalidOperationException(SR.Get(SRID.CacheRequestNeedCache));
throw new InvalidOperationException(SR.CacheRequestNeedCache);
}
}
......@@ -215,7 +215,7 @@ internal static void ValidateCurrent(SafePatternHandle hPattern)
{
if (hPattern.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.CacheRequestNeedLiveForProperties));
throw new InvalidOperationException(SR.CacheRequestNeedLiveForProperties);
}
}
......
......@@ -61,20 +61,20 @@ internal static void RegisterProxyAssembly ( AssemblyName assemblyName )
}
catch(System.IO.FileNotFoundException)
{
throw new ProxyAssemblyNotLoadedException(SR.Get(SRID.Assembly0NotFound,assemblyName));
throw new ProxyAssemblyNotLoadedException(SR.Format(SR.Assembly0NotFound,assemblyName));
}
string typeName = assemblyName.Name + ".UIAutomationClientSideProviders";
Type t = a.GetType( typeName );
if( t == null )
{
throw new ProxyAssemblyNotLoadedException(SR.Get(SRID.CouldNotFindType0InAssembly1, typeName, assemblyName));
throw new ProxyAssemblyNotLoadedException(SR.Format(SR.CouldNotFindType0InAssembly1, typeName, assemblyName));
}
FieldInfo fi = t.GetField("ClientSideProviderDescriptionTable", BindingFlags.Static | BindingFlags.Public);
if (fi == null || fi.FieldType != typeof(ClientSideProviderDescription[]))
{
throw new ProxyAssemblyNotLoadedException(SR.Get(SRID.CouldNotFindRegisterMethodOnType0InAssembly1, typeName, assemblyName));
throw new ProxyAssemblyNotLoadedException(SR.Format(SR.CouldNotFindRegisterMethodOnType0InAssembly1, typeName, assemblyName));
}
ClientSideProviderDescription[] table = fi.GetValue(null) as ClientSideProviderDescription[];
......@@ -734,7 +734,7 @@ private static void AddToProxyDescriptionTable(ClientSideProviderDescription[] p
{
if( pi.ImageName != null || pi.Flags != 0 )
{
throw new ArgumentException(SR.Get(SRID.NonclientClassnameCannotBeUsedWithFlagsOrImagename));
throw new ArgumentException(SR.NonclientClassnameCannotBeUsedWithFlagsOrImagename);
}
_pseudoProxies[j] = pi.ClientSideProviderFactoryCallback;
......
......@@ -1185,7 +1185,7 @@ private static void CheckError(int hr)
{
string description;
if (!UiaGetErrorDescription(out description))
description = SR.Get(SRID.UnknownCoreAPIError);
description = SR.UnknownCoreAPIError;
switch (hr)
{
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Resources;
namespace System
{
internal static partial class SR
{
public static string Get(string name)
{
return GetResourceString(name, null);
}
public static string Get(string name, params object[] args)
{
return Format(GetResourceString(name, null), args);
}
}
}
......@@ -37,7 +37,7 @@ public class AndCondition : Condition
public AndCondition( params Condition [ ] conditions )
{
Misc.ValidateArgumentNonNull( conditions, "conditions" );
Misc.ValidateArgument( conditions.Length >= 2, SRID.MustBeAtLeastTwoConditions );
Misc.ValidateArgument( conditions.Length >= 2, nameof(SR.MustBeAtLeastTwoConditions) );
foreach( Condition condition in conditions )
{
Misc.ValidateArgumentNonNull( condition, "conditions" );
......
......@@ -137,9 +137,9 @@ AutomationEventHandler eventHandler
{
Misc.ValidateArgumentNonNull(element, "element" );
Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" );
Misc.ValidateArgument( eventId != AutomationElement.AutomationFocusChangedEvent, SRID.EventIdMustNotBeAutomationFocusChanged );
Misc.ValidateArgument( eventId != AutomationElement.StructureChangedEvent,SRID.EventIdMustNotBeStructureChanged );
Misc.ValidateArgument( eventId != AutomationElement.AutomationPropertyChangedEvent, SRID.EventIdMustNotBeAutomationPropertyChanged );
Misc.ValidateArgument( eventId != AutomationElement.AutomationFocusChangedEvent, nameof(SR.EventIdMustNotBeAutomationFocusChanged) );
Misc.ValidateArgument( eventId != AutomationElement.StructureChangedEvent, nameof(SR.EventIdMustNotBeStructureChanged) );
Misc.ValidateArgument( eventId != AutomationElement.AutomationPropertyChangedEvent, nameof(SR.EventIdMustNotBeAutomationPropertyChanged) );
if (eventId == WindowPattern.WindowClosedEvent)
{
......@@ -184,7 +184,7 @@ AutomationEventHandler eventHandler
if ( !paramsValidated )
{
throw new ArgumentException( SR.Get( SRID.ParamsNotApplicableToWindowClosedEvent ) );
throw new ArgumentException( SR.ParamsNotApplicableToWindowClosedEvent );
}
}
......@@ -208,9 +208,9 @@ AutomationEventHandler eventHandler
{
Misc.ValidateArgumentNonNull(element, "element" );
Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" );
Misc.ValidateArgument( eventId != AutomationElement.AutomationFocusChangedEvent, SRID.EventIdMustNotBeAutomationFocusChanged );
Misc.ValidateArgument( eventId != AutomationElement.StructureChangedEvent, SRID.EventIdMustNotBeStructureChanged );
Misc.ValidateArgument( eventId != AutomationElement.AutomationPropertyChangedEvent, SRID.EventIdMustNotBeAutomationPropertyChanged );
Misc.ValidateArgument( eventId != AutomationElement.AutomationFocusChangedEvent, nameof(SR.EventIdMustNotBeAutomationFocusChanged) );
Misc.ValidateArgument( eventId != AutomationElement.StructureChangedEvent, nameof(SR.EventIdMustNotBeStructureChanged) );
Misc.ValidateArgument( eventId != AutomationElement.AutomationPropertyChangedEvent, nameof(SR.EventIdMustNotBeAutomationPropertyChanged) );
// Remove the client-side listener for for this event
ClientEventManager.RemoveListener( eventId, element, eventHandler );
......@@ -235,7 +235,7 @@ AutomationEventHandler eventHandler
Misc.ValidateArgumentNonNull(properties, "properties" );
if (properties.Length == 0)
{
throw new ArgumentException( SR.Get(SRID.AtLeastOnePropertyMustBeSpecified) );
throw new ArgumentException( SR.AtLeastOnePropertyMustBeSpecified );
}
// Check that no properties are interpreted properties
......
......@@ -333,7 +333,7 @@ public override int GetHashCode()
{
// Hash codes need to be unique if the runtime ids are null we will end up
// handing out duplicates so throw an exception.
throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
for (int i = 0; i < id.Length; i++)
......@@ -431,7 +431,7 @@ public static AutomationElement FromPoint(Point pt)
/// <returns>element representing root node of specified window</returns>
public static AutomationElement FromHandle(IntPtr hwnd)
{
Misc.ValidateArgument(hwnd != IntPtr.Zero, SRID.HwndMustBeNonNULL);
Misc.ValidateArgument(hwnd != IntPtr.Zero, nameof(SR.HwndMustBeNonNULL));
SafeNodeHandle hnode = UiaCoreApi.UiaNodeFromHandle(hwnd);
if (hnode.IsInvalid)
......@@ -508,7 +508,7 @@ public object GetCurrentPropertyValue(AutomationProperty property, bool ignoreDe
AutomationPropertyInfo pi;
if (!Schema.GetPropertyInfo(property, out pi))
{
return new ArgumentException(SR.Get(SRID.UnsupportedProperty));
return new ArgumentException(SR.UnsupportedProperty);
}
object value;
......@@ -560,7 +560,7 @@ public object GetCurrentPattern(AutomationPattern pattern)
object retObject;
if (!TryGetCurrentPattern(pattern, out retObject))
{
throw new InvalidOperationException(SR.Get(SRID.UnsupportedPattern));
throw new InvalidOperationException(SR.UnsupportedPattern);
}
return retObject;
......@@ -683,7 +683,7 @@ public object GetCachedPattern(AutomationPattern pattern)
object patternObject;
if (!TryGetCachedPattern(pattern, out patternObject))
{
throw new InvalidOperationException(SR.Get(SRID.UnsupportedPattern));
throw new InvalidOperationException(SR.UnsupportedPattern);
}
return patternObject;
}
......@@ -717,7 +717,7 @@ public bool TryGetCachedPattern(AutomationPattern pattern, out object patternObj
AutomationPatternInfo pi;
if (!Schema.GetPatternInfo(pattern, out pi))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedPattern));
throw new ArgumentException(SR.UnsupportedPattern);
}
patternObject = pi.ClientSideWrapper(this, hPattern, true);
......@@ -866,7 +866,7 @@ public void SetFocus()
}
else
{
throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed));
throw new InvalidOperationException(SR.SetFocusFailed);
}
}
......@@ -928,7 +928,7 @@ public Point GetClickablePoint()
{
Point pt;
if ( !TryGetClickablePoint( out pt ) )
throw new NoClickablePointException(SR.Get(SRID.LogicalElementNoClickablePoint));
throw new NoClickablePointException(SR.LogicalElementNoClickablePoint);
return pt;
}
......@@ -1046,7 +1046,7 @@ public AutomationElement CachedParent
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// We've spec'd as throwing an Exception, and that's what we do PreSharp shouldn't complain
#pragma warning suppress 6503
throw new InvalidOperationException(SR.Get(SRID.CachedPropertyNotRequested));
throw new InvalidOperationException(SR.CachedPropertyNotRequested);
}
return _cachedParent;
......@@ -1078,7 +1078,7 @@ public AutomationElementCollection CachedChildren
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// We've spec'd as throwing an Exception, and that's what we do PreSharp shouldn't complain
#pragma warning suppress 6503
throw new InvalidOperationException(SR.Get(SRID.CachedPropertyNotRequested));
throw new InvalidOperationException(SR.CachedPropertyNotRequested);
}
// Build up an array to return - first count the children,
......@@ -1120,7 +1120,7 @@ internal void CheckElement()
{
if (_hnode == null || _hnode.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.CacheRequestNeedElementReference));
throw new InvalidOperationException(SR.CacheRequestNeedElementReference);
}
}
......@@ -1222,7 +1222,7 @@ object LookupCachedValue(AutomationIdentifier id, bool throwIfNotRequested, bool
{
if (throwIfNotRequested)
{
throw new InvalidOperationException(SR.Get(SRID.CachedPropertyNotRequested));
throw new InvalidOperationException(SR.CachedPropertyNotRequested);
}
else
{
......@@ -1253,7 +1253,7 @@ object LookupCachedValue(AutomationIdentifier id, bool throwIfNotRequested, bool
{
if (throwIfNotRequested)
{
throw new InvalidOperationException(SR.Get(SRID.CachedPropertyNotRequested));
throw new InvalidOperationException(SR.CachedPropertyNotRequested);
}
else
{
......@@ -1302,11 +1302,11 @@ private UiaCoreApi.UiaCacheResponse[] Find(TreeScope scope, Condition condition,
Misc.ValidateArgumentNonNull(condition, "condition");
if (scope == 0)
{
throw new ArgumentException(SR.Get(SRID.TreeScopeNeedAtLeastOne));
throw new ArgumentException(SR.TreeScopeNeedAtLeastOne);
}
if ((scope & ~(TreeScope.Element | TreeScope.Children | TreeScope.Descendants)) != 0)
{
throw new ArgumentException(SR.Get(SRID.TreeScopeElementChildrenDescendantsOnly));
throw new ArgumentException(SR.TreeScopeElementChildrenDescendantsOnly);
}
// Set up a find struct...
......
......@@ -198,7 +198,7 @@ public void Pop()
// (no lock needed here, since this is per-thread state)
if (_threadStack == null || _threadStack.Count == 0 || _threadStack.Peek() != this)
{
throw new InvalidOperationException(SR.Get(SRID.CacheReqestCanOnlyPopTop));
throw new InvalidOperationException(SR.CacheReqestCanOnlyPopTop);
}
_threadStack.Pop();
......@@ -303,12 +303,12 @@ public TreeScope TreeScope
{
if (value == 0)
{
throw new ArgumentException(SR.Get(SRID.TreeScopeNeedAtLeastOne));
throw new ArgumentException(SR.TreeScopeNeedAtLeastOne);
}
if ((value & ~(TreeScope.Element | TreeScope.Children | TreeScope.Descendants)) != 0)
{
throw new ArgumentException(SR.Get(SRID.TreeScopeElementChildrenDescendantsOnly));
throw new ArgumentException(SR.TreeScopeElementChildrenDescendantsOnly);
}
lock (_instanceLock)
......@@ -472,7 +472,7 @@ void CheckAccess()
// is never explicitly added to the stack)
if (_refCount != 0 || this == DefaultCacheRequest)
{
throw new InvalidOperationException(SR.Get(SRID.CacheReqestCantModifyWhileActive));
throw new InvalidOperationException(SR.CacheReqestCantModifyWhileActive);
}
}
......
......@@ -130,7 +130,7 @@ private object PropertyValueValidateAndMap(AutomationProperty property, object v
AutomationPropertyInfo info;
if (!Schema.GetPropertyInfo(property, out info))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedProperty));
throw new ArgumentException(SR.UnsupportedProperty);
}
// Check type is appropriate: NotSupported is allowed against any property,
......@@ -141,7 +141,7 @@ private object PropertyValueValidateAndMap(AutomationProperty property, object v
((value == null && expectedType.IsValueType)
|| (value != null && !expectedType.IsAssignableFrom(value.GetType()))))
{
throw new ArgumentException(SR.Get(SRID.PropertyConditionIncorrectType, property.ProgrammaticName, expectedType.Name));
throw new ArgumentException(SR.Format(SR.PropertyConditionIncorrectType, property.ProgrammaticName, expectedType.Name));
}
// Some types are handled differently in managed vs unmanaged - handle those here...
......
......@@ -36,7 +36,7 @@ public class OrCondition : Condition
public OrCondition( params Condition [ ] conditions )
{
Misc.ValidateArgumentNonNull( conditions, "conditions" );
Misc.ValidateArgument( conditions.Length >= 2, SRID.MustBeAtLeastTwoConditions );
Misc.ValidateArgument( conditions.Length >= 2, nameof(SR.MustBeAtLeastTwoConditions) );
foreach( Condition condition in conditions )
{
Misc.ValidateArgumentNonNull( condition, "conditions" );
......
......@@ -127,7 +127,7 @@ void Init(AutomationProperty property, object val, PropertyConditionFlags flags
AutomationPropertyInfo info;
if (!Schema.GetPropertyInfo(property, out info))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedProperty));
throw new ArgumentException(SR.UnsupportedProperty);
}
// Check type is appropriate: NotSupported is allowed against any property,
......@@ -138,12 +138,12 @@ void Init(AutomationProperty property, object val, PropertyConditionFlags flags
((val == null && expectedType.IsValueType)
|| (val != null && !expectedType.IsAssignableFrom(val.GetType()))))
{
throw new ArgumentException(SR.Get(SRID.PropertyConditionIncorrectType, property.ProgrammaticName, expectedType.Name));
throw new ArgumentException(SR.Format(SR.PropertyConditionIncorrectType, property.ProgrammaticName, expectedType.Name));
}
if ((flags & PropertyConditionFlags.IgnoreCase) != 0)
{
Misc.ValidateArgument(val is string, SRID.IgnoreCaseRequiresString);
Misc.ValidateArgument(val is string, nameof(SR.IgnoreCaseRequiresString));
}
// Some types are handled differently in managed vs unmanaged - handle those here...
......
......@@ -98,7 +98,7 @@ public void SetValue(double value)
object readOnly = _el.GetCurrentPropertyValue(IsReadOnlyProperty);
if (readOnly is bool && (bool)readOnly)
{
throw new InvalidOperationException(SR.Get(SRID.ValueReadonly));
throw new InvalidOperationException(SR.ValueReadonly);
}
UiaCoreApi.RangeValuePattern_SetValue(_hPattern, value);
}
......
......@@ -184,12 +184,12 @@ public TextPatternRange FindAttribute(AutomationTextAttribute attribute, object
AutomationAttributeInfo ai;
if(!Schema.GetAttributeInfo(attribute, out ai))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedAttribute));
throw new ArgumentException(SR.UnsupportedAttribute);
}
if (value.GetType() != ai.Type)
{
throw new ArgumentException(SR.Get(SRID.TextAttributeValueWrongType, attribute, ai.Type.Name, value.GetType().Name), "value");
throw new ArgumentException(SR.Format(SR.TextAttributeValueWrongType, attribute, ai.Type.Name, value.GetType().Name), "value");
}
// note: if we implement attributes whose values are logical elements, patterns,
......@@ -221,7 +221,7 @@ public TextPatternRange FindText(string text, bool backward, bool ignoreCase)
// Therefore we can not use IsNullOrEmpty() here, suppress the warning.
Misc.ValidateArgumentNonNull(text, "text");
#pragma warning suppress 6507
Misc.ValidateArgument(text.Length != 0, SRID.TextMustNotBeNullOrEmpty);
Misc.ValidateArgument(text.Length != 0, nameof(SR.TextMustNotBeNullOrEmpty));
SafeTextRangeHandle hResultTextRange = UiaCoreApi.TextRange_FindText(_hTextRange, text, backward, ignoreCase);
return Wrap(hResultTextRange, _pattern);
......@@ -240,7 +240,7 @@ public object GetAttributeValue(AutomationTextAttribute attribute)
AutomationAttributeInfo ai;
if(!Schema.GetAttributeInfo(attribute, out ai))
{
throw new ArgumentException(SR.Get(SRID.UnsupportedAttribute));
throw new ArgumentException(SR.UnsupportedAttribute);
}
object obj = UiaCoreApi.TextRange_GetAttributeValue(_hTextRange, attribute.Id);
......
......@@ -223,7 +223,7 @@ public TextPatternRange RangeFromPoint(Point screenLocation)
Rect rect = (Rect)_element.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
if (screenLocation.X < rect.Left || screenLocation.X >= rect.Right || screenLocation.Y < rect.Top || screenLocation.Y >= rect.Bottom)
{
throw new ArgumentException(SR.Get(SRID.ScreenCoordinatesOutsideBoundingRect));
throw new ArgumentException(SR.ScreenCoordinatesOutsideBoundingRect);
}
SafeTextRangeHandle hTextRange = UiaCoreApi.TextPattern_RangeFromPoint(_hPattern, screenLocation);
......@@ -278,7 +278,7 @@ static internal object Wrap(AutomationElement el, SafePatternHandle hPattern, bo
{
if (hPattern.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.CantPrefetchTextPattern));
throw new InvalidOperationException(SR.CantPrefetchTextPattern);
}
return new TextPattern(el, hPattern);
......
......@@ -85,7 +85,7 @@ public void SetValue( string value )
object readOnly = _el.GetCurrentPropertyValue(IsReadOnlyProperty);
if (readOnly is bool && (bool)readOnly)
{
throw new InvalidOperationException(SR.Get(SRID.ValueReadonly));
throw new InvalidOperationException(SR.ValueReadonly);
}
UiaCoreApi.ValuePattern_SetValue(_hPattern, value);
......
......@@ -17,7 +17,6 @@
<ItemGroup>
<Compile Include="$(WpfSharedDir)RefAssemblyAttrs.cs" />
<Compile Include="$(WpfSharedDir)MS\Win32\NativeMethodsSetLastError.cs" />
<Compile Include="SR.cs" />
<Compile Include="$(WpfCommonDir)src\System\SR.cs">
<Link>Common\System\SR.cs</Link>
</Compile>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册