@@ -15,6 +15,7 @@ record Model(ResourceArea RootArea, string ResourceName)
15
15
static class ResourceFile
16
16
{
17
17
static readonly Regex FormatExpression = new Regex ( "{(?<name>[^{}]+)}" , RegexOptions . Compiled ) ;
18
+ internal static readonly Regex NameReplaceExpression = new Regex ( @"\||:|;|\>|\<" , RegexOptions . Compiled ) ;
18
19
19
20
public static ResourceArea Load ( string fileName , string rootArea )
20
21
{
@@ -33,17 +34,18 @@ public static ResourceArea Load(IEnumerable<XElement> data, string rootArea)
33
34
{
34
35
// Splits: ([resouce area]_)*[resouce name]
35
36
var nameAttribute = element . Attribute ( "name" ) . Value ;
37
+ var id = NameReplaceExpression . Replace ( nameAttribute , "_" ) ;
36
38
var valueElement = element . Element ( "value" ) . Value ;
37
39
var comment = element . Element ( "comment" ) ? . Value ? . Replace ( "<" , "<" ) . Replace ( ">" , ">" ) ;
38
- var areaParts = nameAttribute . Split ( new [ ] { "_" } , StringSplitOptions . RemoveEmptyEntries ) ;
40
+ var areaParts = id . Split ( new [ ] { "_" } , StringSplitOptions . RemoveEmptyEntries ) ;
39
41
if ( areaParts . Length <= 1 )
40
42
{
41
- root . Values . Add ( GetValue ( nameAttribute , valueElement ) with { Comment = comment } ) ;
43
+ root . Values . Add ( GetValue ( id , nameAttribute , valueElement ) with { Comment = comment } ) ;
42
44
}
43
45
else
44
46
{
45
47
var area = GetArea ( root , areaParts . Take ( areaParts . Length - 1 ) ) ;
46
- var value = GetValue ( areaParts . Skip ( areaParts . Length - 1 ) . First ( ) , valueElement ) with { Comment = comment } ;
48
+ var value = GetValue ( areaParts . Skip ( areaParts . Length - 1 ) . First ( ) , nameAttribute , valueElement ) with { Comment = comment } ;
47
49
48
50
area . Values . Add ( value ) ;
49
51
}
@@ -65,13 +67,13 @@ static ResourceArea GetArea(ResourceArea area, IEnumerable<string> areaPath)
65
67
var currentArea = area ;
66
68
foreach ( var areaName in areaPath )
67
69
{
68
- var existing = currentArea . NestedAreas . FirstOrDefault ( a => a . Name == areaName ) ;
70
+ var existing = currentArea . NestedAreas . FirstOrDefault ( a => a . Id == areaName ) ;
69
71
if ( existing == null )
70
72
{
71
73
if ( currentArea . Values . Any ( v => v . Name == areaName ) )
72
74
throw new ArgumentException ( string . Format (
73
75
"Area name '{0}' is already in use as a value name under area '{1}'." ,
74
- areaName , currentArea . Name ) ) ;
76
+ areaName , currentArea . Id ) ) ;
75
77
76
78
existing = new ResourceArea ( areaName , currentArea . Prefix + areaName + "_" ) ;
77
79
currentArea . NestedAreas . Add ( existing ) ;
@@ -83,9 +85,9 @@ static ResourceArea GetArea(ResourceArea area, IEnumerable<string> areaPath)
83
85
return currentArea ;
84
86
}
85
87
86
- static ResourceValue GetValue ( string resourceName , string resourceValue )
88
+ static ResourceValue GetValue ( string resourceId , string resourceName , string resourceValue )
87
89
{
88
- var value = new ResourceValue ( resourceName , resourceValue ) ;
90
+ var value = new ResourceValue ( resourceId , resourceName , resourceValue ) ;
89
91
90
92
// Parse parameter names
91
93
if ( FormatExpression . IsMatch ( resourceValue ) )
@@ -101,15 +103,15 @@ static ResourceValue GetValue(string resourceName, string resourceValue)
101
103
}
102
104
}
103
105
104
- [ DebuggerDisplay ( "Name = {Name }, NestedAreas = {NestedAreas.Count}, Values = {Values.Count}" ) ]
105
- record ResourceArea ( string Name , string Prefix )
106
+ [ DebuggerDisplay ( "Id = {Id }, NestedAreas = {NestedAreas.Count}, Values = {Values.Count}" ) ]
107
+ record ResourceArea ( string Id , string Prefix )
106
108
{
107
109
public List < ResourceArea > NestedAreas { get ; init ; } = new List < ResourceArea > ( ) ;
108
110
public List < ResourceValue > Values { get ; init ; } = new List < ResourceValue > ( ) ;
109
111
}
110
112
111
- [ DebuggerDisplay ( "{Name } = {Value}" ) ]
112
- record ResourceValue ( string Name , string ? Raw )
113
+ [ DebuggerDisplay ( "{Id } = {Value}" ) ]
114
+ record ResourceValue ( string Id , string Name , string ? Raw )
113
115
{
114
116
public string ? Value => Raw ? . Replace ( Environment . NewLine , "" ) ? . Replace ( "<" , "<" ) ? . Replace ( ">" , ">" ) ;
115
117
public string ? Comment { get ; init ; }
0 commit comments