private static IEnumerable <UiaParameterDescription> BuildParamsFromProviderMethodInfo(MethodInfo mInfo) { // Accordingly to UIA docs, In params should go before any Out params var inParams = from parameterInfo in mInfo.GetParameters() where !parameterInfo.IsOut let uiaType = UiaTypesHelper.TypeToAutomationType(parameterInfo.ParameterType) select new UiaParameterDescription(parameterInfo.Name, uiaType); var outParams = from parameterInfo in mInfo.GetParameters() where parameterInfo.IsOut let uiaType = UiaTypesHelper.TypeToOutAutomationType(parameterInfo.ParameterType.GetElementType()) select new UiaParameterDescription(parameterInfo.Name, uiaType); var retParam = Enumerable.Empty <UiaParameterDescription>(); if (mInfo.ReturnType != typeof(void)) { var uiaRetType = UiaTypesHelper.TypeToOutAutomationType(mInfo.ReturnType); var retParamDescr = new UiaParameterDescription(UiaTypesHelper.RetParamUnspeakableName, uiaRetType); retParam = new[] { retParamDescr }; } return(inParams.Concat(outParams).Concat(retParam)); }
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); }
public void DispatchCallToProvider(object provider, UiaParameterListHelper paramList) { if (ProviderMethodInfo == null) { throw new InvalidOperationException("You need to pass providerMethodInfo if you want to call ISchemaMember.DispatchCallToProvider"); } if (paramList.Count != PatternMethodParamDescriptions.Count) { var message = string.Format("Provided paramList has unexpected number of elements. Expected {0} but was {1}", PatternMethodParamDescriptions.Count, paramList.Count); throw new ArgumentException(message, "paramList"); } var providerCallParameters = new object[ProviderMethodInfo.GetParameters().Length]; // fill in params for (int i = 0; i < PatternMethodParamDescriptions.Count; i++) { var desc = PatternMethodParamDescriptions[i]; if (UiaTypesHelper.IsInType(desc.UiaType)) { var providerMethodParamIdx = _providerMethodInfoIndicies[desc.Name]; providerCallParameters[providerMethodParamIdx] = paramList[i]; } } // call provider object result = null; try { result = ProviderMethodInfo.Invoke(provider, providerCallParameters); } catch (TargetInvocationException e) { if (e.InnerException != null) { throw e.InnerException; } throw; } // write back out params for (int i = 0; i < PatternMethodParamDescriptions.Count; i++) { var desc = PatternMethodParamDescriptions[i]; if (desc.Name == UiaTypesHelper.RetParamUnspeakableName) { paramList[i] = result; continue; } if (UiaTypesHelper.IsOutType(desc.UiaType)) { var providerMethodParamIdx = _providerMethodInfoIndicies[desc.Name]; paramList[i] = providerCallParameters[providerMethodParamIdx]; } } }
private UiaPropertyInfoHelper GetPropertyHelper(PropertyInfo pInfo) { var propertyAttr = pInfo.GetAttribute <PatternPropertyAttribute>(); // can'be null as otherwise it wouldn't get into this method var guid = propertyAttr.Guid; var programmaticName = pInfo.Name; var uiaType = UiaTypesHelper.TypeToAutomationType(pInfo.PropertyType); return(new UiaPropertyInfoHelper(guid, programmaticName, uiaType, pInfo.GetPropertyGetter())); }
internal static bool ParametersMatch(Type serverParamType, Type clientParamType) { if (serverParamType.IsByRef != clientParamType.IsByRef) { return(false); } if (UiaTypesHelper.IsElementOnServerSide(serverParamType)) { if (clientParamType.IsByRef) { clientParamType = clientParamType.GetElementType(); } return(UiaTypesHelper.IsElementOnClientSide(clientParamType) || clientParamType == typeof(AutomationElement)); } return(serverParamType == clientParamType); }
private void ReflectStandaloneProperties() { var t = GetType(); var fs = t.GetStaticFieldsMarkedWith <StandalonePropertyAttribute>(); var standaloneProps = new List <UiaPropertyInfoHelper>(); foreach (var fieldInfo in fs) { if (!fieldInfo.Name.EndsWith("Property")) { throw new ArgumentException("Field {0} marked with StandalonePropertyAttribute but named incorrectly. Should be XxxProperty, where Xxx is the programmatic name of the property being registered"); } var programmaticName = fieldInfo.Name.Remove(fieldInfo.Name.Length - "Property".Length); var attr = fieldInfo.GetAttribute <StandalonePropertyAttribute>(); var uiaType = UiaTypesHelper.TypeToAutomationType(attr.Type); standaloneProps.Add(new UiaPropertyInfoHelper(attr.Guid, programmaticName, uiaType)); } if (standaloneProps.Count > 0) { _standaloneProperties = standaloneProps.ToArray(); } }