NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
122 stars 25 forks source link

AttributeArgument.Value.Tostring() causes exception: TypedConstant is an array. Use Values property #92

Closed xumix closed 1 year ago

xumix commented 1 year ago

Tpl code:

{{- for property in cls.Properties | Symbols.ThatArePublic }}
    {{ property.Name | String.ToCamelCase }}{{ property | Custom.NullableMark }}: {{ property | Custom.TsPropertyTypeConverter }};
{{- end}}

Extension code where the exception occurs:

        public static string TsPropertyTypeConverter(IProperty property)
        {
            var type = property.Type;

            var attr = property.Attributes?.FirstOrDefault(x => x.FullName == "Newtonsoft.Json.JsonConverterAttribute");

            if (attr != null && attr.Arguments.Any(x => x.Value.ToString() == "HighPrecisionDecimalConverter";))
            {
                return "string";
            }

            //skipped
        }

The property causing exception:

[JsonConverter(typeof(CustomDateTimeConverter), "dd.MM.yyyy HH:mm:ss", new[] { "dd.MM.yyyy HH:mm" })]
public DateTime EndDate { get; set; }