Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Improve Caliburn.Micro compatibility for auto binding
Browse files Browse the repository at this point in the history
Fix #132
  • Loading branch information
yck1509 committed Dec 9, 2014
1 parent 45c1f0d commit 4816e35
Showing 1 changed file with 54 additions and 22 deletions.
76 changes: 54 additions & 22 deletions Confuser.Renamer/Analyzers/CaliburnAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,67 @@ private void AnalyzeBAMLElement(BAMLAnalyzer analyzer, BamlElement elem) {
var prop = rec as PropertyWithConverterRecord;
if (prop == null)
continue;

var attr = analyzer.ResolveAttribute(prop.AttributeId);
if (attr.Item2 == null || attr.Item2.Name != "Attach")
continue;
var attrDeclType = analyzer.ResolveType(attr.Item2.OwnerTypeId);
if (attrDeclType.FullName != "Caliburn.Micro.Message")
if (attr.Item2 == null)
continue;

string actionStr = prop.Value;
foreach (var msg in actionStr.Split(';')) {
string msgStr;
if (msg.Contains("=")) {
msgStr = msg.Split('=')[1].Trim('[', ']', ' ');
}
else {
msgStr = msg.Trim('[', ']', ' ');
}
if (msgStr.StartsWith("Action"))
msgStr = msgStr.Substring(6);
int parenIndex = msgStr.IndexOf('(');
if (parenIndex != -1)
msgStr = msgStr.Substring(0, parenIndex);

string actName = msgStr.Trim();
foreach (var method in analyzer.LookupMethod(actName))
analyzer.NameService.SetCanRename(method, false);
if (attr.Item2.Name == "Attach")
AnalyzeMessageAttach(analyzer, attr, prop.Value);

if (attr.Item2.Name == "Name")
AnalyzeAutoBind(analyzer, attr, prop.Value);

if (attr.Item2.Name == "MethodName")
AnalyzeActionMessage(analyzer, attr, prop.Value);
}
}

private void AnalyzeMessageAttach(BAMLAnalyzer analyzer, Tuple<IDnlibDef, AttributeInfoRecord, TypeDef> attr, string value) {
var attrDeclType = analyzer.ResolveType(attr.Item2.OwnerTypeId);
if (attrDeclType.FullName != "Caliburn.Micro.Message")
return;

foreach (var msg in value.Split(';')) {
string msgStr;
if (msg.Contains("=")) {
msgStr = msg.Split('=')[1].Trim('[', ']', ' ');
}
else {
msgStr = msg.Trim('[', ']', ' ');
}
if (msgStr.StartsWith("Action"))
msgStr = msgStr.Substring(6);
int parenIndex = msgStr.IndexOf('(');
if (parenIndex != -1)
msgStr = msgStr.Substring(0, parenIndex);

string actName = msgStr.Trim();
foreach (var method in analyzer.LookupMethod(actName))
analyzer.NameService.SetCanRename(method, false);
}
}

private void AnalyzeAutoBind(BAMLAnalyzer analyzer, Tuple<IDnlibDef, AttributeInfoRecord, TypeDef> attr, string value) {
if (!(attr.Item1 is PropertyDef) || ((PropertyDef)attr.Item1).DeclaringType.FullName != "System.Windows.FrameworkElement")
return;

foreach (var method in analyzer.LookupMethod(value))
analyzer.NameService.SetCanRename(method, false);
foreach (var method in analyzer.LookupProperty(value))
analyzer.NameService.SetCanRename(method, false);
}

private void AnalyzeActionMessage(BAMLAnalyzer analyzer, Tuple<IDnlibDef, AttributeInfoRecord, TypeDef> attr, string value) {
var attrDeclType = analyzer.ResolveType(attr.Item2.OwnerTypeId);
if (attrDeclType.FullName != "Caliburn.Micro.ActionMessage")
return;

foreach (var method in analyzer.LookupMethod(value))
analyzer.NameService.SetCanRename(method, false);
}


public void PreRename(ConfuserContext context, INameService service, IDnlibDef def) {
//
}
Expand Down

0 comments on commit 4816e35

Please sign in to comment.