diff --git a/Confuser.Core/DnlibUtils.cs b/Confuser.Core/DnlibUtils.cs index f3d3c5c12..0f755a71c 100644 --- a/Confuser.Core/DnlibUtils.cs +++ b/Confuser.Core/DnlibUtils.cs @@ -269,14 +269,9 @@ static void FindTypeRefsInternal(TypeSig typeSig, IList ret) { /// /// The property. /// true if the specified property is public; otherwise, false. - public static bool IsPublic(this PropertyDef property) { - if (property.GetMethod != null && property.GetMethod.IsPublic) - return true; - - if (property.SetMethod != null && property.SetMethod.IsPublic) - return true; - - return property.OtherMethods.Any(method => method.IsPublic); + public static bool IsPublic (this PropertyDef property) + { + return property.AllMethods ().Any (method => method.IsPublic); } /// @@ -284,14 +279,9 @@ public static bool IsPublic(this PropertyDef property) { /// /// The property. /// true if the specified property is static; otherwise, false. - public static bool IsStatic(this PropertyDef property) { - if (property.GetMethod != null && property.GetMethod.IsStatic) - return true; - - if (property.SetMethod != null && property.SetMethod.IsStatic) - return true; - - return property.OtherMethods.Any(method => method.IsStatic); + public static bool IsStatic (this PropertyDef property) + { + return property.AllMethods ().Any (method => method.IsStatic); } /// @@ -299,17 +289,9 @@ public static bool IsStatic(this PropertyDef property) { /// /// The event. /// true if the specified event is public; otherwise, false. - public static bool IsPublic(this EventDef evt) { - if (evt.AddMethod != null && evt.AddMethod.IsPublic) - return true; - - if (evt.RemoveMethod != null && evt.RemoveMethod.IsPublic) - return true; - - if (evt.InvokeMethod != null && evt.InvokeMethod.IsPublic) - return true; - - return evt.OtherMethods.Any(method => method.IsPublic); + public static bool IsPublic (this EventDef evt) + { + return evt.AllMethods ().Any (method => method.IsPublic); } /// @@ -317,17 +299,53 @@ public static bool IsPublic(this EventDef evt) { /// /// The event. /// true if the specified event is static; otherwise, false. - public static bool IsStatic(this EventDef evt) { - if (evt.AddMethod != null && evt.AddMethod.IsStatic) - return true; + public static bool IsStatic (this EventDef evt) + { + return evt.AllMethods ().Any (method => method.IsStatic); + } + + /// + /// Determines whether the specified method is an explictly implemented interface member. + /// + /// The method. + /// true if the specified method is an explictly implemented interface member; otherwise, false. + public static bool IsExplicitlyImplementedInterfaceMember (this MethodDef method) + { + return method.IsFinal && method.IsPrivate; + } - if (evt.RemoveMethod != null && evt.RemoveMethod.IsStatic) - return true; + /// + /// Determines whether the specified property is an explictly implemented interface member. + /// + /// The method. + /// true if the specified property is an explictly implemented interface member; otherwise, false. + public static bool IsExplicitlyImplementedInterfaceMember (this PropertyDef property) + { + return property.AllMethods ().Any (IsExplicitlyImplementedInterfaceMember); + } - if (evt.InvokeMethod != null && evt.InvokeMethod.IsStatic) - return true; + /// + /// Determines whether the specified event is an explictly implemented interface member. + /// + /// The event. + /// true if the specified eve is an explictly implemented interface member; otherwise, false. + public static bool IsExplicitlyImplementedInterfaceMember (this EventDef evt) + { + return evt.AllMethods ().Any (IsExplicitlyImplementedInterfaceMember); + } + + private static IEnumerable AllMethods (this EventDef evt) + { + return new [] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod } + .Concat (evt.OtherMethods) + .Where (m => m != null); + } - return evt.OtherMethods.Any(method => method.IsStatic); + private static IEnumerable AllMethods (this PropertyDef property) + { + return new [] { property.GetMethod, property.SetMethod } + .Concat (property.OtherMethods) + .Where (m => m != null); } /// diff --git a/Confuser.Renamer/AnalyzePhase.cs b/Confuser.Renamer/AnalyzePhase.cs index a2850f7cc..76b34ac88 100644 --- a/Confuser.Renamer/AnalyzePhase.cs +++ b/Confuser.Renamer/AnalyzePhase.cs @@ -178,6 +178,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters else if (method.IsRuntimeSpecialName) service.SetCanRename(method, false); + else if (method.IsExplicitlyImplementedInterfaceMember()) + service.SetCanRename(method, false); + else if (parameters.GetParameter(context, method, "forceRen", false)) return; @@ -216,6 +219,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters else if (property.IsRuntimeSpecialName) service.SetCanRename(property, false); + else if (property.IsExplicitlyImplementedInterfaceMember()) + service.SetCanRename(property, false); + else if (parameters.GetParameter(context, property, "forceRen", false)) return; @@ -233,6 +239,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters else if (evt.IsRuntimeSpecialName) service.SetCanRename(evt, false); + + else if (evt.IsExplicitlyImplementedInterfaceMember()) + service.SetCanRename (evt, false); } } } \ No newline at end of file