public void AddParameter(UiaParameterDescription param) { if (PatternMethodParamDescriptions.Count > 0 && UiaTypesHelper.IsOutType(PatternMethodParamDescriptions.Last().UiaType) && UiaTypesHelper.IsInType(param.UiaType)) { throw new ArgumentException("In param can't go after an out one. Please, ensure the correct order"); } if (ProviderMethodInfo != null && param.Name != UiaTypesHelper.RetParamUnspeakableName && !_providerMethodInfoIndicies.ContainsKey(param.Name)) { throw new ArgumentException("Provided provider's method info does not have argument with this name"); } UIAutomationType type = param.UiaType; var marshalledName = Marshal.StringToCoTaskMemUni(param.Name); if (UiaTypesHelper.IsInType(type)) { _inParamNames.Add(marshalledName); _inParamTypes.Add(type); } else { _outParamNames.Add(marshalledName); _outParamTypes.Add(type); } PatternMethodParamDescriptions.Add(param); }
/// <summary> /// Usable for general-purpose implementation that uses ISchemaMember.DispatchCallToProvider() /// </summary> /// <param name="getterFromProvider">Lambda for getting property value from pattern provider interface. It should be akin to /// <code>(object p) => ((ISomePatternProvider)p).MyProperty</code>. Or, same thing, /// <code>TypeMember<ISomePatternProvider>.GetPropertyGetter(p => p.MyProperty)</code>. For standalone properties /// it can be null (it is used for pattern handler implementation only, which doesn't take part in getting standalone properties).</param> public UiaPropertyInfoHelper(Guid propertyGuid, string programmaticName, UIAutomationType propertyType, Func <object, object> getterFromProvider) { _programmaticName = programmaticName; _propertyGuid = propertyGuid; _propertyType = propertyType; _getterFromProvider = getterFromProvider; }
/// <summary> /// Usable for general-purpose implementation that uses ISchemaMember.DispatchCallToProvider() /// </summary> /// <param name="getterFromProvider">Lambda for getting property value from pattern provider interface. It should be akin to /// <code>(object p) => ((ISomePatternProvider)p).MyProperty</code>. Or, same thing, /// <code>TypeMember<ISomePatternProvider>.GetPropertyGetter(p => p.MyProperty)</code>. For standalone properties /// it can be null (it is used for pattern handler implementation only, which doesn't take part in getting standalone properties).</param> public UiaPropertyInfoHelper(Guid propertyGuid, string programmaticName, UIAutomationType propertyType, Func<object, object> getterFromProvider) { _programmaticName = programmaticName; _propertyGuid = propertyGuid; _propertyType = propertyType; _getterFromProvider = getterFromProvider; }
// Compute a CLR type from its UIA type private Type ClrTypeFromUiaType(UIAutomationType uiaType) { // Mask off the out flag, which we don't care about. uiaType = (UIAutomationType)((int)uiaType & (int)~UIAutomationType.UIAutomationType_Out); switch (uiaType) { case UIAutomationType.UIAutomationType_Int: return(typeof(int)); case UIAutomationType.UIAutomationType_Bool: return(typeof(int)); // These are BOOL, not bool case UIAutomationType.UIAutomationType_String: return(typeof(string)); case UIAutomationType.UIAutomationType_Double: return(typeof(double)); case UIAutomationType.UIAutomationType_Element: return((_onClientSide) ? typeof(IUIAutomationElement) : typeof(IRawElementProviderSimple)); default: throw new ArgumentException("Type not supported by UIAutomationType"); } }
private void AssertPropertyInfo(string programmaticName, UIAutomationType uiaType, string guid, UiaPropertyInfoHelper propInfo) { var data = propInfo.Data; Assert.AreEqual(programmaticName, data.pProgrammaticName); Assert.AreEqual(uiaType, data.type); Assert.AreEqual(new Guid(guid), data.guid); }
public UiaParameterHelper(UIAutomationType type) { _uiaType = type; _clrType = ClrTypeFromUiaType(type); _marshalledData = Marshal.AllocCoTaskMem(GetSizeOfMarshalledData()); _ownsData = true; // It is a safe assumption that if we are initialized without incoming data, // we are on the client side. If this changes, we can make this an explicit parameter. _onClientSide = true; }
public UiaParameterHelper(UIAutomationType type, IntPtr marshalledData) { _uiaType = type; _clrType = ClrTypeFromUiaType(type); _marshalledData = marshalledData; _ownsData = false; GC.SuppressFinalize(this); // It is a safe assumption that if we are initialized with incoming data, // we are on the provider side. If this changes, we can make this an explicit parameter. _onClientSide = false; }
public int RegisterCustomProperty(Guid id, string name, UIAutomationType type) { UIAutomationPropertyInfo info = new UIAutomationPropertyInfo { guid = id, pProgrammaticName = name, type = type, }; _uiaRegistrar.RegisterProperty(ref info, out int dynamicId); return dynamicId; }
public void RegisterCustomProperty_SamePropertyTwise_ReturnsSameNonZeroValue() { using (Registrar r = new Registrar()) { Guid id = Guid.NewGuid(); const string name = "My property name"; const UIAutomationType type = UIAutomationType.UIAutomationType_Bool; int dynamicId1 = r.RegisterCustomProperty(id, name, type); int dynamicId2 = r.RegisterCustomProperty(id, name, type); Assert.AreNotEqual(0, dynamicId1); Assert.AreEqual(dynamicId1, dynamicId2); } }
/// <summary> /// Suitable for standalone properties that do not require handlers, hence no need to use ISchemaMember.DispatchCallToProvider() ever. /// </summary> public UiaPropertyInfoHelper(Guid propertyGuid, string programmaticName, UIAutomationType propertyType) : this(propertyGuid, programmaticName, propertyType, null) { }
// Compute a CLR type from its UIA type private Type ClrTypeFromUiaType(UIAutomationType uiaType) { // Mask off the out flag, which we don't care about. uiaType = (UIAutomationType) ((int) uiaType & (int) ~UIAutomationType.UIAutomationType_Out); switch (uiaType) { case UIAutomationType.UIAutomationType_Int: return typeof (int); case UIAutomationType.UIAutomationType_Bool: return typeof (int); // These are BOOL, not bool case UIAutomationType.UIAutomationType_String: return typeof (string); case UIAutomationType.UIAutomationType_Double: return typeof (double); case UIAutomationType.UIAutomationType_Element: return (_onClientSide) ? typeof (IUIAutomationElement) : typeof (IRawElementProviderSimple); default: throw new ArgumentException("Type not supported by UIAutomationType"); } }
public static bool IsInType(UIAutomationType type) { return(!IsOutType(type)); }
public static bool IsOutType(UIAutomationType type) { return((type & UIAutomationType.UIAutomationType_Out) != 0); }
public UiaParameterDescription(string name, UIAutomationType type) { _name = name; _uiaType = type; }
public static bool IsInType(UIAutomationType type) { return !IsOutType(type); }
public static bool IsOutType(UIAutomationType type) { return (type & UIAutomationType.UIAutomationType_Out) != 0; }