Skip to content

Commit cf1d633

Browse files
author
Sébastien Geiser
committed
Version 1.0.0.0 of CodingSebLocalization.Fody
Add PropertyChangedTriggerMethodNameForLocalization attribute and management
1 parent e4da6f7 commit cf1d633

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

CodingSeb.Localization.FodyAddin.Fody/Extensions.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,35 @@ public static bool IsINotifyPropertyChanged(this TypeDefinition typeDefinition)
4040

4141
public static MethodDefinition FindPropertyChangedTriggerMethod(this TypeDefinition typeDefinition)
4242
{
43-
if (typeDefinition?.FullName.Equals("System.Object") != false)
44-
return null;
45-
else if (typeDefinition.Methods.SingleOrDefault(m => propertyChangedTriggerMethodCommonNames.Any(name => name.Equals(m.Name, StringComparison.OrdinalIgnoreCase))) is MethodDefinition method)
46-
return method;
47-
else if (typeDefinition.BaseType is TypeDefinition parentTypeDefinition)
48-
return parentTypeDefinition.FindPropertyChangedTriggerMethod();
49-
else
50-
return null;
43+
bool removeFirstEntry = false;
44+
45+
var attribute = typeDefinition.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name.Equals("PropertyChangedTriggerMethodNameForLocalization"));
46+
47+
if(attribute != null)
48+
{
49+
propertyChangedTriggerMethodCommonNames.Insert(0, attribute.ConstructorArguments[0].Value.ToString());
50+
51+
removeFirstEntry = true;
52+
}
53+
54+
try
55+
{
56+
if (typeDefinition?.FullName.Equals("System.Object") != false)
57+
return null;
58+
else if (typeDefinition.Methods.FirstOrDefault(m => propertyChangedTriggerMethodCommonNames.Any(name => name.Equals(m.Name, StringComparison.OrdinalIgnoreCase))) is MethodDefinition method)
59+
return method;
60+
else if (typeDefinition.BaseType is TypeDefinition parentTypeDefinition)
61+
return parentTypeDefinition.FindPropertyChangedTriggerMethod();
62+
else
63+
return null;
64+
}
65+
finally
66+
{
67+
if(removeFirstEntry)
68+
{
69+
propertyChangedTriggerMethodCommonNames.RemoveAt(0);
70+
}
71+
}
5172
}
5273

5374
public static MethodDefinition FindNearestFinalizeParentMethod(this TypeDefinition typeDefinition)

CodingSeb.Localization.FodyAddin/GlobalSuppressions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
using System.Diagnostics.CodeAnalysis;
77

88
[assembly: SuppressMessage("Redundancy", "RCS1163:Unused parameter.", Justification = "<Pending>", Scope = "member", Target = "~M:CodingSeb.Localization.LocalizeAttribute.#ctor(System.String)")]
9+
[assembly: SuppressMessage("Redundancy", "RCS1163:Unused parameter.", Justification = "<Pending>", Scope = "member", Target = "~M:CodingSeb.Localization.PropertyChangedTriggerMethodNameForLocalization.#ctor(System.String)")]
10+
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>", Scope = "member", Target = "~M:CodingSeb.Localization.PropertyChangedTriggerMethodNameForLocalization.#ctor(System.String)")]
11+
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>", Scope = "member", Target = "~M:CodingSeb.Localization.LocalizeAttribute.#ctor(System.String)")]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace CodingSeb.Localization
4+
{
5+
/// <summary>
6+
/// To specify the name of the method that trigger the PropertyChanged event if not a standard one.
7+
/// The method will be use to triggger PropertyChanged when Current Language changed
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Class)]
10+
public class PropertyChangedTriggerMethodNameForLocalization : Attribute
11+
{
12+
/// <summary>
13+
/// Constructor
14+
/// </summary>
15+
/// <param name="methodName">The name of the method that trigger the PropertyChanged event</param>
16+
public PropertyChangedTriggerMethodNameForLocalization(string methodName)
17+
{}
18+
}
19+
}

0 commit comments

Comments
 (0)