|
6 | 6 | using System.Collections.Immutable; |
7 | 7 | using System.Diagnostics.CodeAnalysis; |
8 | 8 | using System.Linq; |
| 9 | +using CommunityToolkit.GeneratedDependencyProperty.Extensions; |
9 | 10 | using Microsoft.CodeAnalysis; |
10 | 11 |
|
11 | 12 | namespace CommunityToolkit.GeneratedDependencyProperty.Models; |
@@ -53,8 +54,12 @@ public static TypedConstantInfo Create(TypedConstant arg) |
53 | 54 | ushort ush => new Primitive.Of<ushort>(ush), |
54 | 55 | _ => throw new ArgumentException("Invalid primitive type") |
55 | 56 | }, |
56 | | - (TypedConstantKind.Type, ITypeSymbol type) => new Type(type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)), |
57 | | - (TypedConstantKind.Enum, object value) => new Enum(arg.Type!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), value), |
| 57 | + (TypedConstantKind.Type, ITypeSymbol type) |
| 58 | + => new Type(type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)), |
| 59 | + (TypedConstantKind.Enum, object value) when arg.Type!.TryGetEnumFieldName(value, out string? fieldName) |
| 60 | + => new KnownEnum(arg.Type!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), fieldName), |
| 61 | + (TypedConstantKind.Enum, object value) |
| 62 | + => new Enum(arg.Type!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), value), |
58 | 63 | _ => throw new ArgumentException("Invalid typed constant type"), |
59 | 64 | }; |
60 | 65 | } |
@@ -87,7 +92,10 @@ public static bool TryCreate(IOperation operation, [NotNullWhen(true)] out Typed |
87 | 92 | { |
88 | 93 | ({ SpecialType: SpecialType.System_String }, string text) => new Primitive.String(text), |
89 | 94 | ({ SpecialType: SpecialType.System_Boolean}, bool flag) => new Primitive.Boolean(flag), |
90 | | - (INamedTypeSymbol { TypeKind: TypeKind.Enum }, object value) => new Enum(operationType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), value), |
| 95 | + (INamedTypeSymbol { TypeKind: TypeKind.Enum }, object value) when (operationType.TryGetEnumFieldName(value, out string? fieldName)) |
| 96 | + => new KnownEnum(operationType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), fieldName), |
| 97 | + (INamedTypeSymbol { TypeKind: TypeKind.Enum }, object value) |
| 98 | + => new Enum(operationType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), value), |
91 | 99 | (_, byte b) => new Primitive.Of<byte>(b), |
92 | 100 | (_, char c) => new Primitive.Of<char>(c), |
93 | 101 | (_, double d) => new Primitive.Of<double>(d), |
|
0 commit comments