private string GetChangeManagedNameActionResult(TypeInfo typeInfo, ConvType convType, string oldName) { if (Settings.m_ruleSet != null) { ICategory category = TypeCategory.GetInstance(); TypeInfoMatchTarget target = null; using (TypeAttr attr = typeInfo.GetTypeAttr()) { TypeLibTypes.Interop.TYPEKIND kind = attr.typekind; target = new TypeInfoMatchTarget(typeInfo.GetContainingTypeLib(), typeInfo, kind); } AbstractActionManager actionManager = RuleEngine.GetActionManager(); List <Rule> changeNameRules = Settings.m_ruleSet.GetRule( category, ChangeManagedNameActionDef.GetInstance(), target); if (changeNameRules.Count != 0) { if (changeNameRules.Count > 1) { Output.WriteWarning(Resource.FormatString("Wrn_RuleMultipleMatch", ChangeManagedNameActionDef.GetInstance()), WarningCode.Wrn_RuleMultipleMatch); } Rule changeNameRule = changeNameRules[changeNameRules.Count - 1]; int namespaceSplit = oldName.LastIndexOf('.'); string oldNamespace = ""; if (namespaceSplit != -1) { oldNamespace = oldName.Substring(0, namespaceSplit + 1); } return(oldNamespace + (changeNameRule.Action as ChangeManagedNameAction).NewName); } } return(oldName); }
private bool RuleEngineResolveRedirection(RuleSet ruleSet, TypeInfo typeInfo, out Type convertedType) { convertedType = null; if (ruleSet != null) { ICategory category = TypeCategory.GetInstance(); TypeLibTypes.Interop.TYPEKIND typeKind; using (TypeAttr attr = typeInfo.GetTypeAttr()) { typeKind = attr.typekind; } TypeInfoMatchTarget target = new TypeInfoMatchTarget(typeInfo.GetContainingTypeLib(), typeInfo, typeKind); AbstractActionManager actionManager = RuleEngine.GetActionManager(); List <Rule> resolveToRules = ruleSet.GetRule( category, ResolveToActionDef.GetInstance(), target); if (resolveToRules.Count != 0) { if (resolveToRules.Count > 1) { Output.WriteWarning(Resource.FormatString("Wrn_RuleMultipleMatch", ResolveToActionDef.GetInstance().GetActionName()), WarningCode.Wrn_RuleMultipleMatch); } Rule resolveToRule = resolveToRules[resolveToRules.Count - 1]; ResolveToAction action = resolveToRule.Action as ResolveToAction; try { Assembly assembly = Assembly.ReflectionOnlyLoad(action.AssemblyName); convertedType = assembly.GetType(action.ManagedTypeFullName); return(true); } catch (Exception) { Output.WriteWarning(Resource.FormatString("Wrn_CannotLoadResolveToType", action.ManagedTypeFullName, action.AssemblyName), WarningCode.Wrn_CannotLoadResolveToType); } } } return(false); }
private void actionComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (actionComboBox.SelectedItem == null) { return; } string actionName = actionComboBox.SelectedItem as string; AbstractActionManager actionManager = RuleEngine.GetActionManager(); IActionDef actionDef = actionManager.GetActionDef(actionName); if (actionDef == null) { return; } string actionDescription = Resource.FormatString("Msg_ActionDescription_" + actionDef.GetActionName()); textBoxDescription.Text = actionDescription; CheckOKButtonEnabled(); }
private void categoryComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (categoryComboBox.SelectedItem == null) { return; } string categoryName = categoryComboBox.SelectedItem as string; AbstractCategoryManager categoryManager = RuleEngine.GetCategoryManager(); ICategory category = categoryManager.GetCategory(categoryName); AbstractActionManager actionManager = RuleEngine.GetActionManager(); List <IActionDef> actionDefList = actionManager.GetPossibleActionDefList(category); actionComboBox.Items.Clear(); foreach (IActionDef actionDef in actionDefList) { actionComboBox.Items.Add(actionDef.GetActionName()); } actionComboBox.SelectedIndex = -1; CheckOKButtonEnabled(); }
protected void DefineType(ConverterInfo info, TypeInfo typeInfo, bool dealWithAlias) { m_info = info; m_typeInfo = typeInfo; if (dealWithAlias) { m_nonAliasedTypeInfo = ConvCommon.GetAlias(typeInfo); } else { m_nonAliasedTypeInfo = typeInfo; } try { OnDefineType(); // // Emit SuppressUnmanagedCodeSecurityAttribute for /unsafe switch // if ((m_info.Settings.m_flags & TypeLibImporterFlags.UnsafeInterfaces) != 0) { if (ConvType != ConvType.ClassInterface && ConvType != ConvType.EventInterface) { m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForSuppressUnmanagedCodeSecurity()); } } // Rule Engine AddAttributeAction if (m_info.Settings.m_ruleSet != null) { ICategory category = TypeCategory.GetInstance(); TypeInfoMatchTarget target = null; using (TypeAttr attr = m_typeInfo.GetTypeAttr()) { TypeLibTypes.Interop.TYPEKIND kind = attr.typekind; target = new TypeInfoMatchTarget(m_typeInfo.GetContainingTypeLib(), m_typeInfo, kind); } AbstractActionManager actionManager = RuleEngine.GetActionManager(); List <Rule> addAttributeRules = m_info.Settings.m_ruleSet.GetRule( category, AddAttributeActionDef.GetInstance(), target); foreach (Rule rule in addAttributeRules) { AddAttributeAction addAttributeAction = rule.Action as AddAttributeAction; ConstructorInfo attributeCtor; byte[] blob; bool success = true; if (addAttributeAction.GetCustomAttribute(out attributeCtor, out blob)) { try { m_typeBuilder.SetCustomAttribute(attributeCtor, blob); } catch (Exception) { success = false; } } else { success = false; } if (!success) { string name = m_typeInfo.GetDocumentation(); string msg = Resource.FormatString("Wrn_AddCustomAttributeFailed", addAttributeAction.TypeName, name); m_info.ReportEvent(WarningCode.Wrn_AddCustomAttributeFailed, msg); } } } } catch (ReflectionTypeLoadException) { throw; // Fatal failure. Throw } catch (TlbImpResolveRefFailWrapperException) { throw; // Fatal failure. Throw } catch (TlbImpGeneralException) { throw; // Fatal failure. Throw } catch (Exception) { string name = String.Empty; if (m_typeInfo != null) { try { name = m_typeInfo.GetDocumentation(); } catch (Exception) { } } if (name != String.Empty) { string msg = Resource.FormatString("Wrn_InvalidTypeInfo", name); m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo, msg); } else { string msg = Resource.FormatString("Wrn_InvalidTypeInfo_Unnamed"); m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo_Unnamed, msg); } // When failure, try to create the type anyway if (m_typeBuilder != null) { m_type = m_typeBuilder.CreateType(); } } }