public override bool Match(IMatchTarget matchTarget) { string nativeSignature; if (matchTarget is SignatureInfoMatchTarget) { SignatureInfoMatchTarget sigInfoMatchTarget = matchTarget as SignatureInfoMatchTarget; nativeSignature = sigInfoMatchTarget.NativeSignature; } else { throw new CannotApplyConditionToMatchTargetException(this, matchTarget); } return(m_operator.IsTrue("" + nativeSignature, m_value)); }
public override bool Match(IMatchTarget matchTarget) { int parameterIndex = 0; if (matchTarget is SignatureInfoMatchTarget) { SignatureInfoMatchTarget sigInfoMatchTarget = matchTarget as SignatureInfoMatchTarget; parameterIndex = sigInfoMatchTarget.NativeParameterIndex; } else { throw new CannotApplyConditionToMatchTargetException(this, matchTarget); } return(m_operator.IsTrue("" + parameterIndex, m_value)); }
private NativeParameterIndexCondition GetNativeParameterIndexCondition( SignatureInfoMatchTarget signatureInfoMatchTarget) { NativeParameterIndexConditionDef parameterIndexConditionDef = NativeParameterIndexConditionDef.GetInstance(); var parameterIndexCondition = parameterIndexConditionDef.Create() as NativeParameterIndexCondition; parameterIndexCondition.Operator = EqualOperator.GetInstance(); parameterIndexCondition.Value = "" + signatureInfoMatchTarget.NativeParameterIndex; return parameterIndexCondition; }
private static void ProcessFuncParams(TypeInfo interfaceTypeInfo, int funcIndex, TreeNode parentTreeNode) { int paramIndex = 0; FuncDesc funcDesc = interfaceTypeInfo.GetFuncDesc(funcIndex); ElemDesc retElemDesc = funcDesc.elemdescFunc; SignatureInfoMatchTarget retSignatureInfo = new SignatureInfoMatchTarget(interfaceTypeInfo, funcIndex, retElemDesc, paramIndex); TreeNode retTreeNode = new TreeNode(); string typeString = (new TlbType2String(interfaceTypeInfo, retElemDesc.tdesc)).GetTypeString(); retTreeNode.Text = typeString + " " + retSignatureInfo.Name + ": " + retSignatureInfo.Type; retTreeNode.Tag = retSignatureInfo; SetTlbTreeNodeImage(retTreeNode); parentTreeNode.Nodes.Add(retTreeNode); ++paramIndex; // Parameters //string[] signatureNames = interfaceTypeInfo.GetNames(funcDesc.memid, funcDesc.cParams + 1); for (int i = 0; i < funcDesc.cParams; ++i) { ElemDesc paramElemDesc = funcDesc.GetElemDesc(i); typeString = (new TlbType2String(interfaceTypeInfo, paramElemDesc.tdesc)).GetTypeString(); //string signatureName = signatureNames[i + 1]; //if (signatureName.Trim().Equals("")) // signatureName = "_unnamed_arg_" + paramIndex; SignatureInfoMatchTarget paramSignatureInfo = new SignatureInfoMatchTarget( interfaceTypeInfo, funcIndex, paramElemDesc, paramIndex); TreeNode paramTreeNode = new TreeNode(); paramTreeNode.Text = typeString + " " + paramSignatureInfo.Name + ": " + paramSignatureInfo.Type; ++paramIndex; paramTreeNode.Tag = paramSignatureInfo; SetTlbTreeNodeImage(paramTreeNode); parentTreeNode.Nodes.Add(paramTreeNode); } }
private static void GetTypeFromConvertToAction(SignatureInfoMatchTarget target, ConvertToAction convertToAction, ConverterInfo converterInfo, TypeInfo typeInfo, TypeDesc typeDesc, out Type typeReturn, out CustomAttributeBuilder customAttribute, out ParameterAttributes fixedParameterAttributes) { typeReturn = null; customAttribute = null; fixedParameterAttributes = ParameterAttributes.None; ParameterDirection direction = ConvertToActionConstants.GetParameterDirection(convertToAction.Direction); switch (direction) { case ParameterDirection.IN: fixedParameterAttributes |= ParameterAttributes.In; break; case ParameterDirection.OUT: fixedParameterAttributes |= ParameterAttributes.Out; break; case ParameterDirection.INOUT: fixedParameterAttributes |= ParameterAttributes.In; fixedParameterAttributes |= ParameterAttributes.Out; break; } Dictionary<string, string> attributePairDictionary = ConvertToAction.GetConvertToAttributeDictionary(convertToAction.Attributes); ManagedTypeConvertTo managedType = ConvertToActionConstants.GetManagedTypeConvertTo(convertToAction.ManagedTypeConvertTo); UnmanagedType marshalAs = ConvertToActionConstants.GetMarshalAs(convertToAction.UnmanagedTypeMarshalAs); switch (managedType) { case ManagedTypeConvertTo.LPARRAY: if ((VarEnum)typeDesc.vt == VarEnum.VT_CARRAY || (VarEnum)typeDesc.vt == VarEnum.VT_PTR) { TypeConverter elemTypeConverter = new TypeConverter(converterInfo, typeInfo, typeDesc.lptdesc, ConversionType.Element); Type elemType = elemTypeConverter.ConvertedType; typeReturn = elemType.MakeArrayType(); if (attributePairDictionary.ContainsKey(ConvertToActionDef.SizeConst)) { customAttribute = CustomAttributeHelper.GetBuilderForMarshalAsConstArray(UnmanagedType.LPArray, Int32.Parse(attributePairDictionary[ConvertToActionDef.SizeConst].ToString())); } else if (attributePairDictionary.ContainsKey(ConvertToActionDef.SizeParamIndex)) { customAttribute = CustomAttributeHelper.GetBuilderForMarshalAsConstArrayBySizeParamIndex( UnmanagedType.LPArray, Int16.Parse(attributePairDictionary[ConvertToActionDef.SizeParamIndex].ToString())); } else if (attributePairDictionary.ContainsKey(ConvertToActionDef.SizeParamIndexOffset)) { customAttribute = CustomAttributeHelper.GetBuilderForMarshalAsConstArrayBySizeParamIndex( UnmanagedType.LPArray, (short)((target.NativeParameterIndex) - 1 + Int16.Parse(attributePairDictionary[ConvertToActionDef.SizeParamIndexOffset].ToString()))); } else { customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(UnmanagedType.LPArray); } } else { string targetTypeString = new TlbType2String(typeInfo, typeDesc).GetTypeString(); throw new TlbImpGeneralException(Resource.FormatString("Err_ConvertNonArrayToArray", targetTypeString), ErrorCode.Err_ConvertNonArrayToArray); } break; case ManagedTypeConvertTo.DECIMAL: typeReturn = typeof(Decimal); if (marshalAs != (UnmanagedType)(-1)) customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(marshalAs); break; case ManagedTypeConvertTo.INT: typeReturn = typeof(int); if (marshalAs != (UnmanagedType)(-1)) customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(marshalAs); break; case ManagedTypeConvertTo.OBJECT: typeReturn = typeof(object); if (marshalAs != (UnmanagedType)(-1)) customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(marshalAs); break; case ManagedTypeConvertTo.STRING: typeReturn = typeof(string); if (marshalAs != (UnmanagedType)(-1)) customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(marshalAs); break; case ManagedTypeConvertTo.STRINGBUILDER: typeReturn = typeof(StringBuilder); if (marshalAs != (UnmanagedType)(-1)) customAttribute = CustomAttributeHelper.GetBuilderForMarshalAs(marshalAs); break; } if (convertToAction.ByRef) { typeReturn = typeReturn.MakeByRefType(); } }
private static void GetRuledReturnTypeConverter(InterfaceInfo info, InterfaceMemberInfo memInfo, FuncDesc func, out TypeConverter convertToReturnConverter) { convertToReturnConverter = null; Rule convertToRule = null; if (memInfo.Index != -1) { // Is not event delegate. SignatureInfoMatchTarget returnTarget = new SignatureInfoMatchTarget( info.RefTypeInfo, memInfo.Index, func.elemdescFunc, 0); if (info.ConverterInfo.Settings.m_ruleSet != null) { ICategory signatureCategory = SignatureCategory.GetInstance(); AbstractActionManager actionManager = RuleEngine.GetActionManager(); List<Rule> convertToRules = info.ConverterInfo.Settings.m_ruleSet.GetRule( signatureCategory, ConvertToActionDef.GetInstance(), returnTarget); if (convertToRules.Count != 0) { if (convertToRules.Count > 1) { Output.WriteWarning( Resource.FormatString("Wrn_RuleMultipleMatch", ConvertToActionDef.GetInstance().GetActionName()), WarningCode.Wrn_RuleMultipleMatch); } convertToRule = convertToRules[convertToRules.Count - 1]; } } if (convertToRule != null) { var convertToAction = convertToRule.Action as ConvertToAction; Type typeReturn; CustomAttributeBuilder customAttribute; ParameterAttributes fixedParameterAttributes; GetTypeFromConvertToAction(returnTarget, convertToAction, info.ConverterInfo, info.RefTypeInfo, func.elemdescFunc.tdesc, out typeReturn, out customAttribute, out fixedParameterAttributes); convertToReturnConverter = new TypeConverter(typeReturn, customAttribute, fixedParameterAttributes); } } }
private static void GetRuledParameterTypeConverters(InterfaceInfo info, InterfaceMemberInfo memInfo, FuncDesc func, out List<TypeConverter> convertToParameterConverterList) { int cParams = func.cParams; convertToParameterConverterList = new List<TypeConverter>(); short n; for (n = 0; n < cParams; ++n) { ElemDesc elem = func.GetElemDesc(n); ParamDesc paramDesc = elem.paramdesc; // "ConvertTo" for basic types and array // Rule Engine Rule convertToRule = null; if (memInfo.Index != -1) { // Is not event delegate. SignatureInfoMatchTarget target = new SignatureInfoMatchTarget( info.RefTypeInfo, memInfo.Index, elem, n + 1); if (info.ConverterInfo.Settings.m_ruleSet != null) { ICategory signatureCategory = SignatureCategory.GetInstance(); AbstractActionManager actionManager = RuleEngine.GetActionManager(); List<Rule> convertToRules = info.ConverterInfo.Settings.m_ruleSet.GetRule( signatureCategory, ConvertToActionDef.GetInstance(), target); if (convertToRules.Count != 0) { if (convertToRules.Count > 1) { Output.WriteWarning( Resource.FormatString("Wrn_RuleMultipleMatch", ConvertToActionDef.GetInstance().GetActionName()), WarningCode.Wrn_RuleMultipleMatch); } convertToRule = convertToRules[convertToRules.Count - 1]; } } if (convertToRule != null) { var convertToAction = convertToRule.Action as ConvertToAction; Type typeReturn; CustomAttributeBuilder customAttribute; ParameterAttributes fixedParameterAttributes; GetTypeFromConvertToAction(target, convertToAction, info.ConverterInfo, info.RefTypeInfo, elem.tdesc, out typeReturn, out customAttribute, out fixedParameterAttributes); convertToParameterConverterList.Add( new TypeConverter(typeReturn, customAttribute, fixedParameterAttributes)); } else { convertToParameterConverterList.Add(null); } } else { convertToParameterConverterList.Add(null); } } }