Skip to content

Commit 892abc9

Browse files
authored
Fix processing dump output in custom attributes (#94)
***UPDATE_DEPENDENTS***
1 parent 1e965af commit 892abc9

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal partial class DumpTemplates
5252
5353
{{#each Attributes}}
5454
Attribute: {{Name}}::[{{ReferenceId}} {{TypeToken}}]{{#newline}}
55-
{{#if FixedArgs}}Fixed Arguments:{{#newline}}{{/if}}
55+
{{#if FixedArgs}}Fixed Arguments:{{#newline}}{{#else}}{{#newline}}{{/if}}
5656
{{#each FixedArgs}}
5757
{{Options}} {{Numeric}}{{Text}}{{#newline}}
5858
{{#newline}}

source/MetadataProcessor.Core/nanoDumperGenerator.cs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,7 @@ private void DumpCustomAttributes(DumpAllTable dumpTable)
7575
{
7676
foreach (var value in ma.CustomAttributes[0].ConstructorArguments)
7777
{
78-
var serializationType = value.Type.ToSerializationType();
79-
attribute.FixedArgs.Add(
80-
new AttFixedArgs()
81-
{
82-
Options = ((byte)serializationType).ToString("X2"),
83-
Numeric = serializationType == nanoSerializationType.ELEMENT_TYPE_STRING ? 0.ToString("X16") : ((int)value.Value).ToString("X16"),
84-
Text = serializationType == nanoSerializationType.ELEMENT_TYPE_STRING ? (string)value.Value : "",
85-
}
86-
);
78+
attribute.FixedArgs.Add(BuildFixedArgsAttribute(value));
8779
}
8880
}
8981

@@ -106,14 +98,7 @@ private void DumpCustomAttributes(DumpAllTable dumpTable)
10698
{
10799
foreach (var value in fa.CustomAttributes[0].ConstructorArguments)
108100
{
109-
attribute.FixedArgs.Add(
110-
new AttFixedArgs()
111-
{
112-
Options = ((byte)value.Type.ToSerializationType()).ToString("X2"),
113-
Numeric = ((int)value.Value).ToString("X16"),
114-
Text = ""
115-
}
116-
);
101+
attribute.FixedArgs.Add(BuildFixedArgsAttribute(value));
117102
}
118103
}
119104

@@ -132,21 +117,43 @@ private void DumpCustomAttributes(DumpAllTable dumpTable)
132117
{
133118
foreach (var value in a.CustomAttributes[0].ConstructorArguments)
134119
{
135-
attribute1.FixedArgs.Add(
136-
new AttFixedArgs()
137-
{
138-
Options = ((byte)value.Type.ToSerializationType()).ToString("X2"),
139-
Numeric = ((int)value.Value).ToString("X16"),
140-
Text = ""
141-
}
142-
);
120+
attribute1.FixedArgs.Add(BuildFixedArgsAttribute(value));
143121
}
144122
}
145123

146124
dumpTable.Attributes.Add(attribute1);
147125
}
148126
}
149127

128+
private AttFixedArgs BuildFixedArgsAttribute(CustomAttributeArgument value)
129+
{
130+
var serializationType = value.Type.ToSerializationType();
131+
132+
var newArg = new AttFixedArgs()
133+
{
134+
Options = ((byte)serializationType).ToString("X2"),
135+
Numeric = 0.ToString("X16"),
136+
Text = "",
137+
};
138+
139+
switch(serializationType)
140+
{
141+
case nanoSerializationType.ELEMENT_TYPE_BOOLEAN:
142+
newArg.Numeric = ((bool)value.Value) ? 1.ToString("X16") : 0.ToString("X16");
143+
break;
144+
145+
case nanoSerializationType.ELEMENT_TYPE_STRING:
146+
newArg.Text = (string)value.Value;
147+
break;
148+
149+
default:
150+
newArg.Numeric = ((int)value.Value).ToString("X16");
151+
break;
152+
}
153+
154+
return newArg;
155+
}
156+
150157
private void DumpUserStrings(DumpAllTable dumpTable)
151158
{
152159
// start at 1, because 0 is the empty string entry

0 commit comments

Comments
 (0)