本文整理汇总了C#中INameService.RandomName方法的典型用法代码示例。如果您正苦于以下问题:C# INameService.RandomName方法的具体用法?C# INameService.RandomName怎么用?C# INameService.RandomName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INameService
的用法示例。
在下文中一共展示了INameService.RandomName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreRename
public void PreRename(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
var module = def as ModuleDefMD;
if (module == null || !parameters.GetParameter<bool>(context, def, "renXaml", true))
return;
var wpfResInfo = context.Annotations.Get<Dictionary<string, Dictionary<string, BamlDocument>>>(module, BAMLKey);
if (wpfResInfo == null)
return;
foreach (var res in wpfResInfo.Values)
foreach (var doc in res.Values) {
List<IBAMLReference> references;
if (bamlRefs.TryGetValue(doc.DocumentName, out references)) {
var newName = doc.DocumentName.ToUpperInvariant();
#region old code
//if (newName.EndsWith(".BAML"))
// newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".baml";
//else if (newName.EndsWith(".XAML"))
// newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".xaml";
#endregion
#region Niks patch fix
/*
* Nik's patch for maintaining relative paths. If the xaml file is referenced in this manner
* "/some.namespace;component/somefolder/somecontrol.xaml"
* then we want to keep the relative path and namespace intact. We should be obfuscating it like this - /some.namespace;component/somefolder/asjdjh2398498dswk.xaml
* */
string[] completePath = newName.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
string newShinyName = string.Empty;
for (int i = 0; i <= completePath.Length - 2; i++) {
newShinyName += completePath[i].ToLowerInvariant() + "/";
}
if (newName.EndsWith(".BAML"))
newName = newShinyName + service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".baml";
else if (newName.EndsWith(".XAML"))
newName = newShinyName + service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".xaml";
context.Logger.Debug(String.Format("Preserving virtual paths. Replaced {0} with {1}", doc.DocumentName, newName));
#endregion
bool renameOk = true;
foreach (var bamlRef in references)
if (!bamlRef.CanRename(doc.DocumentName, newName)) {
renameOk = false;
break;
}
if (renameOk) {
foreach (var bamlRef in references)
bamlRef.Rename(doc.DocumentName, newName);
doc.DocumentName = newName;
}
}
}
}
示例2: PreRename
public void PreRename(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
{
var module = def as ModuleDefMD;
if (module == null || !parameters.GetParameter<bool>(context, def, "renXaml", true))
return;
var wpfResInfo = context.Annotations.Get<Dictionary<string, Dictionary<string, BamlDocument>>>(module, BAMLKey);
if (wpfResInfo == null)
return;
foreach (var res in wpfResInfo.Values)
foreach (var doc in res.Values) {
List<IBAMLReference> references;
if (bamlRefs.TryGetValue(doc.DocumentName, out references)) {
var newName = doc.DocumentName.ToUpperInvariant();
if (newName.EndsWith(".BAML"))
newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".baml";
else if (newName.EndsWith(".XAML"))
newName = service.RandomName(RenameMode.Letters).ToLowerInvariant() + ".xaml";
bool renameOk = true;
foreach (var bamlRef in references)
if (!bamlRef.CanRename(doc.DocumentName, newName)) {
renameOk = false;
break;
}
if (renameOk) {
foreach (var bamlRef in references)
bamlRef.Rename(doc.DocumentName, newName);
doc.DocumentName = newName;
}
}
}
}