Skip to content

Commit 90a9a43

Browse files
Fixes TypeNameObjectFormatter.Skim
Be sure to consider the format of TypeNameObject when skimming.
1 parent 2fec9f4 commit 90a9a43

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TypeNameObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public TypeNameObject(int index)
7474
_stringValue = null;
7575
}
7676

77-
public TypeNameObject(string? typeName)
77+
public TypeNameObject(string? stringValue)
7878
{
79-
Debug.Assert(typeName is null || !s_typeNameToIndex.ContainsKey(typeName));
79+
Debug.Assert(stringValue is null || !s_typeNameToIndex.ContainsKey(stringValue));
8080

8181
_index = null;
82-
_stringValue = typeName;
82+
_stringValue = stringValue;
8383
}
8484

8585
public bool IsNull => _index is null && _stringValue is null;

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Serialization/MessagePack/Formatters/TagHelpers/TypeNameObjectFormatter.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ public override void Serialize(ref MessagePackWriter writer, TypeNameObject valu
5757
writer.Write((int)TypeNameKind.Index);
5858
writer.Write(index);
5959
}
60-
else
60+
else if (value.StringValue is string stringValue)
6161
{
6262
writer.Write((int)TypeNameKind.String);
63-
CachedStringFormatter.Instance.Serialize(ref writer, value.GetTypeName(), options);
63+
CachedStringFormatter.Instance.Serialize(ref writer, stringValue, options);
64+
}
65+
else
66+
{
67+
Assumed.Unreachable();
6468
}
6569
}
6670

@@ -73,7 +77,16 @@ public override void Skim(ref MessagePackReader reader, SerializerCachingOptions
7377

7478
reader.ReadArrayHeaderAndVerify(PropertyCount);
7579

76-
reader.Skip(); // TypeNameKind
77-
CachedStringFormatter.Instance.Skim(ref reader, options); // Name
80+
var typeNameKind = (TypeNameKind)reader.ReadInt32();
81+
switch (typeNameKind)
82+
{
83+
case TypeNameKind.Index:
84+
reader.Skip(); // Index
85+
break;
86+
87+
case TypeNameKind.String:
88+
CachedStringFormatter.Instance.Skim(ref reader, options); // StringValue
89+
break;
90+
}
7891
}
7992
}

0 commit comments

Comments
 (0)