本文整理汇总了C#中Rule.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Rule.Add方法的具体用法?C# Rule.Add怎么用?C# Rule.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rule
的用法示例。
在下文中一共展示了Rule.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtectStub
/// <summary>
/// Protects the stub using original project settings replace the current output with the protected stub.
/// </summary>
/// <param name="context">The working context.</param>
/// <param name="fileName">The result file name.</param>
/// <param name="module">The stub module.</param>
/// <param name="snKey">The strong name key.</param>
/// <param name="prot">The packer protection that applies to the stub.</param>
protected void ProtectStub(ConfuserContext context, string fileName, byte[] module, StrongNameKey snKey, Protection prot = null) {
string tmpDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string outDir = Path.Combine(tmpDir, Path.GetRandomFileName());
Directory.CreateDirectory(tmpDir);
for (int i = 0; i < context.OutputModules.Count; i++) {
string path = Path.GetFullPath(Path.Combine(tmpDir, context.OutputPaths[i]));
var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
File.WriteAllBytes(path, context.OutputModules[i]);
}
File.WriteAllBytes(Path.Combine(tmpDir, fileName), module);
var proj = new ConfuserProject();
proj.Seed = context.Project.Seed;
foreach (Rule rule in context.Project.Rules)
proj.Rules.Add(rule);
proj.Add(new ProjectModule {
Path = fileName
});
proj.BaseDirectory = tmpDir;
proj.OutputDirectory = outDir;
foreach (var path in context.Project.ProbePaths)
proj.ProbePaths.Add(path);
proj.ProbePaths.Add(context.Project.BaseDirectory);
PluginDiscovery discovery = null;
if (prot != null) {
var rule = new Rule {
Preset = ProtectionPreset.None,
Inherit = true,
Pattern = "true"
};
rule.Add(new SettingItem<Protection> {
Id = prot.Id,
Action = SettingItemAction.Add
});
proj.Rules.Add(rule);
discovery = new PackerDiscovery(prot);
}
try {
ConfuserEngine.Run(new ConfuserParameters {
Logger = new PackerLogger(context.Logger),
PluginDiscovery = discovery,
Marker = new PackerMarker(snKey),
Project = proj,
PackerInitiated = true
}, context.token).Wait();
}
catch (AggregateException ex) {
context.Logger.Error("Failed to protect packer stub.");
throw new ConfuserException(ex);
}
context.OutputModules = new[] { File.ReadAllBytes(Path.Combine(outDir, fileName)) };
context.OutputPaths = new[] { fileName };
}
示例2: WordGeneratorTest
public void WordGeneratorTest()
{
Rule ruleD = new Rule("D", Combinable.Y, RuleType.SFX);
ruleD.Add(new RuleItem("0","d","e"));
ruleD.Add(new RuleItem("y", "ied", "[^aeiou]y"));
ruleD.Add(new RuleItem("0", "ed", "[^ey]"));
ruleD.Add(new RuleItem("0", "ed", "[aeiou]y"));
Rule ruleG = new Rule("G", Combinable.Y, RuleType.SFX);
ruleG.Add(new RuleItem("e", "ing", "e"));
ruleG.Add(new RuleItem("0", "ing", "[^e]"));
AffixRules rules = new AffixRules();
rules.Add(ruleD);
rules.Add(ruleG);
DictionaryItemWithFlags item = new DictionaryItemWithFlags("create", "DG");
List<string> words = rules.GetPossibleWords(item);
List<string> correctWords = new List<string>()
{
"create", "created", "creating"
};
CollectionAssert.AreEqual(correctWords, words);
Rule ruleH = new Rule("H", Combinable.Y, RuleType.SFX);
ruleH.Add(new RuleItem("0", "u", "[^ey]"));
ruleH.Add(new RuleItem("0", "e", "[^eyghkc]"));
ruleH.Add(new RuleItem("0", "em", "[^ey]"));
ruleH.Add(new RuleItem("0", "y", "[^ey]"));
ruleH.Add(new RuleItem("0", "ů", "[^ey]"));
ruleH.Add(new RuleItem("0", "ům", "[^ey]"));
ruleH.Add(new RuleItem("0", "ech", "[^eyghk]"));
ruleH.Add(new RuleItem("g", "zích", "g"));
ruleH.Add(new RuleItem("h", "zích", "[^c]h"));
ruleH.Add(new RuleItem("ch", "ších", "ch"));
ruleH.Add(new RuleItem("k", "cích", "k"));
ruleH.Add(new RuleItem("e", "u", "e"));
ruleH.Add(new RuleItem("0", "m", "e"));
ruleH.Add(new RuleItem("e", "y", "e"));
ruleH.Add(new RuleItem("e", "ů", "e"));
ruleH.Add(new RuleItem("e", "ům", "e"));
ruleH.Add(new RuleItem("e", "ech", "e"));
ruleH.Add(new RuleItem("y", "ů", "y"));
ruleH.Add(new RuleItem("y", "ům", "y"));
ruleH.Add(new RuleItem("y", "ech", "[^ghk]y"));
ruleH.Add(new RuleItem("gy", "zích", "gy"));
ruleH.Add(new RuleItem("hy", "zích", "[^c]hy"));
ruleH.Add(new RuleItem("chy", "ších", "chy"));
ruleH.Add(new RuleItem("ky", "cích", "ky"));
rules = new AffixRules();
rules.Add(ruleH);
words = rules.GetPossibleWords(new DictionaryItemWithFlags("abakus", "H"));
correctWords = new List<string>()
{
"abakus",
"abakusu",
"abakuse",
"abakusem",
"abakusy",
"abakusů",
"abakusům",
"abakusech"
};
CollectionAssert.AreEqual(correctWords, words);
Rule ruleN = new Rule("N", Combinable.Y, RuleType.PFX);
ruleN.Add(new RuleItem("0", "ne", "."));
Rule ruleE = new Rule("E", Combinable.Y, RuleType.PFX);
ruleE.Add(new RuleItem("0", "nej", "."));
rules = new AffixRules();
rules.Add(ruleN);
rules.Add(ruleE);
words = rules.GetPossibleWords(new DictionaryItemWithFlags("méně", "NE"));
correctWords = new List<string>()
{
"méně",
"neméně",
"nejméně"
};
CollectionAssert.AreEqual(correctWords, words);
Rule ruleX = new Rule("X", Combinable.Y, RuleType.SFX);
ruleX.Add(new RuleItem("a", "ouc", "a"));
ruleX.Add(new RuleItem("a", "ouce", "a"));
rules = new AffixRules();
rules.Add(ruleN);
rules.Add(ruleX);
//.........这里部分代码省略.........
示例3: CreateSampleTestFilter
private TestCaseFilter CreateSampleTestFilter()
{
TestCaseFilter filter = new TestCaseFilter();
RuleGroup group1 = new RuleGroup()
{
Name = "Group1",
Description = "This is the first group.",
RuleGroupType = RuleType.Selector
};
Rule rule1 = new Rule()
{
Name = "Rule1",
SelectStatus = RuleSelectStatus.Selected
};
Rule rule11 = new Rule()
{
Name = "Rule11",
SelectStatus = RuleSelectStatus.Selected,
CategoryList = new System.Collections.Generic.List<string>() { "Cat1", "Cat2", "Cat3" }
};
Rule rule12 = new Rule()
{
Name = "Rule12",
SelectStatus = RuleSelectStatus.NotSelected,
CategoryList = new System.Collections.Generic.List<string>() { "Cat4", "Cat5", "Cat6" }
};
rule1.Add(rule11);
rule1.Add(rule12);
group1.Add(rule1);
RuleGroup group2 = new RuleGroup()
{
Name = "Group2",
Description = "This is the second group.",
RuleGroupType = RuleType.Selector
};
Rule rule2 = new Rule()
{
Name = "Rule2",
SelectStatus = RuleSelectStatus.NotSelected,
CategoryList = new System.Collections.Generic.List<string>() { "Cat1", "Cat2", "Cat3" }
};
group2.Add(rule2);
RuleGroup group3 = new RuleGroup()
{
Name = "Group3",
Description = "This is the third group.",
SelectStatus = RuleSelectStatus.Selected,
RuleGroupType = RuleType.Remover
};
Rule rule3 = new Rule()
{
Name = "Rule3",
SelectStatus = RuleSelectStatus.Selected,
CategoryList = new System.Collections.Generic.List<string>() { "Cat7", "Cat8" }
};
group3.Add(rule3);
filter.Add(group1);
filter.Add(group2);
filter.Add(group3);
rule11.SelectStatus = RuleSelectStatus.Selected;
rule3.SelectStatus = RuleSelectStatus.NotSelected;
return filter;
}