Restore explicitly overridden props/events
This commit is contained in:
parent
04940d785c
commit
6073106cfe
|
@ -461,8 +461,26 @@ namespace de4dot.renamer {
|
||||||
void restoreVirtualProperties(IEnumerable<MethodNameScope> allScopes) {
|
void restoreVirtualProperties(IEnumerable<MethodNameScope> allScopes) {
|
||||||
if (!RestoreProperties)
|
if (!RestoreProperties)
|
||||||
return;
|
return;
|
||||||
foreach (var scope in allScopes)
|
foreach (var scope in allScopes) {
|
||||||
restoreVirtualProperties(scope);
|
restoreVirtualProperties(scope);
|
||||||
|
restoreExplicitVirtualProperties(scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void restoreExplicitVirtualProperties(MethodNameScope scope) {
|
||||||
|
if (scope.Methods.Count != 1)
|
||||||
|
return;
|
||||||
|
var propMethod = scope.Methods[0];
|
||||||
|
if (propMethod.Property != null)
|
||||||
|
return;
|
||||||
|
if (propMethod.MethodDefinition.Overrides.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var theProperty = getOverriddenProperty(propMethod);
|
||||||
|
if (theProperty == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
createProperty(theProperty, propMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreVirtualProperties(MethodNameScope scope) {
|
void restoreVirtualProperties(MethodNameScope scope) {
|
||||||
|
@ -485,15 +503,18 @@ namespace de4dot.renamer {
|
||||||
if (missingProps == null)
|
if (missingProps == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var method in missingProps) {
|
foreach (var method in missingProps)
|
||||||
if (!method.Owner.HasModule)
|
createProperty(prop, method);
|
||||||
continue;
|
}
|
||||||
|
|
||||||
if (method.MethodDefinition.MethodReturnType.ReturnType.FullName == "System.Void")
|
void createProperty(PropertyDef propDef, MethodDef methodDef) {
|
||||||
createPropertySetter(prop.PropertyDefinition.Name, method);
|
if (!methodDef.Owner.HasModule)
|
||||||
else
|
return;
|
||||||
createPropertyGetter(prop.PropertyDefinition.Name, method);
|
|
||||||
}
|
if (methodDef.MethodDefinition.MethodReturnType.ReturnType.FullName == "System.Void")
|
||||||
|
createPropertySetter(propDef.PropertyDefinition.Name, methodDef);
|
||||||
|
else
|
||||||
|
createPropertyGetter(propDef.PropertyDefinition.Name, methodDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
void restorePropertiesFromNames(IEnumerable<MethodNameScope> allScopes) {
|
void restorePropertiesFromNames(IEnumerable<MethodNameScope> allScopes) {
|
||||||
|
@ -611,8 +632,10 @@ namespace de4dot.renamer {
|
||||||
void restoreVirtualEvents(IEnumerable<MethodNameScope> allScopes) {
|
void restoreVirtualEvents(IEnumerable<MethodNameScope> allScopes) {
|
||||||
if (!RestoreEvents)
|
if (!RestoreEvents)
|
||||||
return;
|
return;
|
||||||
foreach (var scope in allScopes)
|
foreach (var scope in allScopes) {
|
||||||
restoreVirtualEvents(scope);
|
restoreVirtualEvents(scope);
|
||||||
|
restoreExplicitVirtualEvents(scope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EventMethodType {
|
enum EventMethodType {
|
||||||
|
@ -623,6 +646,23 @@ namespace de4dot.renamer {
|
||||||
Raiser,
|
Raiser,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restoreExplicitVirtualEvents(MethodNameScope scope) {
|
||||||
|
if (scope.Methods.Count != 1)
|
||||||
|
return;
|
||||||
|
var eventMethod = scope.Methods[0];
|
||||||
|
if (eventMethod.Event != null)
|
||||||
|
return;
|
||||||
|
if (eventMethod.MethodDefinition.Overrides.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
MethodDef overriddenMethod;
|
||||||
|
var theEvent = getOverriddenEvent(eventMethod, out overriddenMethod);
|
||||||
|
if (theEvent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
createEvent(theEvent, eventMethod, getEventMethodType(overriddenMethod));
|
||||||
|
}
|
||||||
|
|
||||||
void restoreVirtualEvents(MethodNameScope scope) {
|
void restoreVirtualEvents(MethodNameScope scope) {
|
||||||
if (scope.Methods.Count <= 1 || !scope.hasEvent())
|
if (scope.Methods.Count <= 1 || !scope.hasEvent())
|
||||||
return;
|
return;
|
||||||
|
@ -638,14 +678,7 @@ namespace de4dot.renamer {
|
||||||
}
|
}
|
||||||
else if (evt == null) {
|
else if (evt == null) {
|
||||||
evt = method.Event;
|
evt = method.Event;
|
||||||
if (evt.AddMethod == method)
|
methodType = getEventMethodType(method);
|
||||||
methodType = EventMethodType.Adder;
|
|
||||||
else if (evt.RemoveMethod == method)
|
|
||||||
methodType = EventMethodType.Remover;
|
|
||||||
else if (evt.RaiseMethod == method)
|
|
||||||
methodType = EventMethodType.Raiser;
|
|
||||||
else
|
|
||||||
methodType = EventMethodType.Other;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (evt == null)
|
if (evt == null)
|
||||||
|
@ -653,21 +686,37 @@ namespace de4dot.renamer {
|
||||||
if (missingEvents == null)
|
if (missingEvents == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var method in missingEvents) {
|
foreach (var method in missingEvents)
|
||||||
if (!method.Owner.HasModule)
|
createEvent(evt, method, methodType);
|
||||||
continue;
|
}
|
||||||
|
|
||||||
switch (methodType) {
|
void createEvent(EventDef eventDef, MethodDef methodDef, EventMethodType methodType) {
|
||||||
case EventMethodType.Adder:
|
if (!methodDef.Owner.HasModule)
|
||||||
createEventAdder(evt.EventDefinition.Name, method);
|
return;
|
||||||
break;
|
|
||||||
case EventMethodType.Remover:
|
switch (methodType) {
|
||||||
createEventRemover(evt.EventDefinition.Name, method);
|
case EventMethodType.Adder:
|
||||||
break;
|
createEventAdder(eventDef.EventDefinition.Name, methodDef);
|
||||||
}
|
break;
|
||||||
|
case EventMethodType.Remover:
|
||||||
|
createEventRemover(eventDef.EventDefinition.Name, methodDef);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EventMethodType getEventMethodType(MethodDef method) {
|
||||||
|
var evt = method.Event;
|
||||||
|
if (evt == null)
|
||||||
|
return EventMethodType.None;
|
||||||
|
if (evt.AddMethod == method)
|
||||||
|
return EventMethodType.Adder;
|
||||||
|
if (evt.RemoveMethod == method)
|
||||||
|
return EventMethodType.Remover;
|
||||||
|
if (evt.RaiseMethod == method)
|
||||||
|
return EventMethodType.Raiser;
|
||||||
|
return EventMethodType.Other;
|
||||||
|
}
|
||||||
|
|
||||||
void restoreEventsFromNames(IEnumerable<MethodNameScope> allScopes) {
|
void restoreEventsFromNames(IEnumerable<MethodNameScope> allScopes) {
|
||||||
if (!RestoreEventsFromNames)
|
if (!RestoreEventsFromNames)
|
||||||
return;
|
return;
|
||||||
|
@ -1023,8 +1072,13 @@ namespace de4dot.renamer {
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDef getOverriddenEvent(MethodDef overrideMethod) {
|
EventDef getOverriddenEvent(MethodDef overrideMethod) {
|
||||||
|
MethodDef overriddenMethod;
|
||||||
|
return getOverriddenEvent(overrideMethod, out overriddenMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventDef getOverriddenEvent(MethodDef overrideMethod, out MethodDef overriddenMethod) {
|
||||||
var theMethod = overrideMethod.MethodDefinition.Overrides[0];
|
var theMethod = overrideMethod.MethodDefinition.Overrides[0];
|
||||||
var overriddenMethod = modules.resolve(theMethod);
|
overriddenMethod = modules.resolve(theMethod);
|
||||||
if (overriddenMethod != null)
|
if (overriddenMethod != null)
|
||||||
return overriddenMethod.Event;
|
return overriddenMethod.Event;
|
||||||
|
|
||||||
|
@ -1034,9 +1088,9 @@ namespace de4dot.renamer {
|
||||||
var extTypeDef = modules.resolveOther(extType);
|
var extTypeDef = modules.resolveOther(extType);
|
||||||
if (extTypeDef == null)
|
if (extTypeDef == null)
|
||||||
return null;
|
return null;
|
||||||
var theMethodDef = extTypeDef.find(theMethod);
|
overriddenMethod = extTypeDef.find(theMethod);
|
||||||
if (theMethodDef != null)
|
if (overriddenMethod != null)
|
||||||
return theMethodDef.Event;
|
return overriddenMethod.Event;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user