Skip to content

Commit 4a538cf

Browse files
committed
Merge branch 'hotfix/attributevalues'
2 parents 7d72b6b + 56fec31 commit 4a538cf

5 files changed

Lines changed: 40 additions & 11 deletions

File tree

JsonTestClasses.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ public class FooNumerics : FooBase
6464
public decimal? NullableDecimal { get; set; }
6565
}
6666

67+
public enum FooEnum
68+
{
69+
Foo = 0,
70+
Bar = 1,
71+
}
72+
6773
/// <summary>
6874
/// Enums.
6975
/// </summary>
7076
public class FooWithEnum : FooBase
7177
{
72-
public enum FooEnum
73-
{
74-
Foo = 0,
75-
Bar = 1,
76-
}
7778

7879
public FooEnum EnumMember { get; set; }
7980
}
@@ -206,11 +207,18 @@ public class FooAttributes
206207
[System.Text.Json.JsonPropertyName(Name = "Last_Name")]
207208
public string Lastname { get; set; }
208209

210+
[Test(new int[1] { 42 }, FooEnum.Bar, typeof(string))]
209211
[DataMember(Name = "YesNo")]
210212
public bool BoolProperty { get; set; }
211213
}
214+
215+
public class TestAttribute : Attribute
216+
{
217+
public TestAttribute(int[] foos, FooEnum @enum, Type type) { }
218+
}
212219
}
213220

221+
214222
// These are here so the attribute test works. This is a standalone file without references, so Roslyn won't know the attributes otherwise.
215223
namespace Newtonsoft.Json
216224
{

src/CodeCaster.SerializeThis.Serialization.Roslyn/AttributeDataExtensions.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,32 @@ public static AttributeInfo[] Map(this ImmutableArray<AttributeData> attributes)
1414
: attributes.Select(a => new AttributeInfo
1515
{
1616
Name = a.AttributeClass.GetTypeName(withGenericParameterNames: true),
17-
ConstructorArguments = a.ConstructorArguments.Select(ca => ca.Value).ToArray(),
18-
Properties = a.NamedArguments.ToDictionary(na => na.Key, na => na.Value.Value),
17+
ConstructorArguments = a.ConstructorArguments.Select(GetValue).ToArray(),
18+
Properties = a.NamedArguments.ToDictionary(na => na.Key, na => GetValue(na.Value)),
1919
})
2020
.ToArray();
2121
}
22+
23+
private static object GetValue(TypedConstant typedConstant)
24+
{
25+
switch (typedConstant.Kind)
26+
{
27+
case TypedConstantKind.Array:
28+
return typedConstant.Values.Select(GetValue).ToArray();
29+
30+
case TypedConstantKind.Primitive:
31+
case TypedConstantKind.Enum:
32+
return typedConstant.Value;
33+
34+
case TypedConstantKind.Type:
35+
return typedConstant.Value is ITypeSymbol typeSymbol
36+
? $"typeof({typeSymbol.GetTypeName()})"
37+
: typedConstant.Value?.GetType().Name;
38+
39+
case TypedConstantKind.Error:
40+
default:
41+
return null;
42+
}
43+
}
2244
}
2345
}

src/CodeCaster.SerializeThis.Serialization.Roslyn/TypeSymbolParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Collections.Immutable;
43
using System.Linq;
54
using Microsoft.CodeAnalysis;
65

src/CodeCaster.SerializeThis/Package/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="SerializeThis.CodeCaster.ca0c8664-e98d-434b-b54e-cafb6f0b1279" Version="1.4.2" Language="en-US" Publisher="CodeCaster" />
4+
<Identity Id="SerializeThis.CodeCaster.ca0c8664-e98d-434b-b54e-cafb6f0b1279" Version="1.4.3" Language="en-US" Publisher="CodeCaster" />
55
<DisplayName>CodeCaster.SerializeThis</DisplayName>
66
<Description xml:space="preserve">Serialize types directly from the IDE.</Description>
77
<MoreInfo>https://github.com/CodeCasterNL/CodeCaster.SerializeThis/blob/master/README.md</MoreInfo>

src/SolutionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
[assembly: AssemblyCopyright("Copyright © CodeCaster 2016-2021")]
55
[assembly: AssemblyTrademark("")]
66

7-
[assembly: AssemblyVersion("1.4.2.0")]
8-
[assembly: AssemblyFileVersion("1.4.2.0")]
7+
[assembly: AssemblyVersion("1.4.3.0")]
8+
[assembly: AssemblyFileVersion("1.4.3.0")]

0 commit comments

Comments
 (0)