|
9 | 9 | using Microsoft.TypeSpec.Generator.EmitterRpc; |
10 | 10 | using Microsoft.TypeSpec.Generator.Expressions; |
11 | 11 | using Microsoft.TypeSpec.Generator.Input; |
| 12 | +using Microsoft.TypeSpec.Generator.Input.Extensions; |
12 | 13 | using Microsoft.TypeSpec.Generator.Primitives; |
13 | 14 | using Microsoft.TypeSpec.Generator.SourceInput; |
14 | 15 | using Microsoft.TypeSpec.Generator.Statements; |
@@ -49,10 +50,30 @@ protected TypeProvider() : this(null) |
49 | 50 | _declaringTypeName.Value); |
50 | 51 |
|
51 | 52 | private protected virtual TypeProvider? BuildLastContractView(string? generatedTypeName = null, string? generatedTypeNamespace = null) |
52 | | - => CodeModelGenerator.Instance.SourceInputModel.FindForTypeInLastContract( |
53 | | - generatedTypeNamespace ?? CustomCodeView?.Type.Namespace ?? BuildNamespace(), |
54 | | - generatedTypeName ?? CustomCodeView?.Name ?? BuildName(), |
| 53 | + { |
| 54 | + var typeNamespace = generatedTypeNamespace ?? CustomCodeView?.Type.Namespace ?? BuildNamespace(); |
| 55 | + var typeName = generatedTypeName ?? CustomCodeView?.Name ?? BuildName(); |
| 56 | + var lastContractView = CodeModelGenerator.Instance.SourceInputModel.FindForTypeInLastContract( |
| 57 | + typeNamespace, |
| 58 | + typeName, |
| 59 | + _declaringTypeName.Value); |
| 60 | + if (lastContractView is not null || _inputType is null || _inputType.IsExactName) |
| 61 | + { |
| 62 | + return lastContractView; |
| 63 | + } |
| 64 | + |
| 65 | + var originalName = _inputType.Name.ToIdentifierName(); |
| 66 | + var normalizedOriginalName = originalName.NormalizeCSharpAcronyms(); |
| 67 | + if (normalizedOriginalName == originalName || typeName != normalizedOriginalName) |
| 68 | + { |
| 69 | + return null; |
| 70 | + } |
| 71 | + |
| 72 | + return CodeModelGenerator.Instance.SourceInputModel.FindForTypeInLastContract( |
| 73 | + typeNamespace, |
| 74 | + originalName, |
55 | 75 | _declaringTypeName.Value); |
| 76 | + } |
56 | 77 |
|
57 | 78 | private static string? GetDeclaringTypeName(TypeProvider? declaringTypeProvider) |
58 | 79 | { |
@@ -801,9 +822,11 @@ private void ResetMembersBasedOnIdentityChange(string? name = null, string? @nam |
801 | 822 | _customCodeView = new(BuildCustomCodeView(name ?? Type.Name, @namespace ?? Type.Namespace)); |
802 | 823 | name = _customCodeView.Value?.Name ?? name ?? Type.Name; |
803 | 824 | @namespace = _customCodeView.Value?.Type.Namespace ?? @namespace ?? Type.Namespace; |
804 | | - _lastContractView = new(BuildLastContractView( |
| 825 | + var lastContractView = BuildLastContractView( |
805 | 826 | name, |
806 | | - @namespace)); |
| 827 | + @namespace); |
| 828 | + _lastContractView = new(lastContractView); |
| 829 | + name = _customCodeView.Value?.Name ?? lastContractView?.Name ?? name; |
807 | 830 | // recalculate declaration modifiers and constructors |
808 | 831 | _declarationModifiers = null; |
809 | 832 | // constructors might change based on declaration modifier changes |
|
0 commit comments